<?php
/**
 *description:出库
 *author:李飞
 *time:2016/12/29
 */

namespace Admin\Controller;
use Think\Controller;
class OutboundController extends CommonController {
	
    public function index(){
		$this->redirect('pushorder');
    }
	public function printorder(){
		$this->display();
    }
	public function printorder_green(){
		$this->display();
    }
	public function printorder_picklist(){
		$this->display();
    }
	public function own_delivery(){
		$this->display();
    }
	public function pushorder_emergency(){
		$make_max=C('BASE_CONFIG.make_max');//最大制单数
		$this->assign('is_emergency',1);
		$this->assign('make_max',$make_max);
		$this->display('pushorder');
    }
	public function pushorder(){
		$make_max=C('BASE_CONFIG.make_max');//最大制单数
		$this->assign('make_max',$make_max);
		$this->display();
    }
	public function order_emergency(){
		$this->display();
    }
    public function freez_log(){
        $this->display();
    }
	//核放单
	public function nuclear_order(){
		
		$this->display();
    }
	public function pushorderlist(){
		$this->display();
    }
	public function pushorderlist_emergency(){
		$this->assign('is_emergency',1);
		$this->display('pushorderlist');
    }
	public function statistical_storage(){
		$this->display();
	}
	
	public function get_statistical_storage(){
		$m=M('StatisticalStorage',C('DB_PRS'),C('DB_DEPOT'));
		$this->make_statistical_storage();
		
		$cate=I('cate');
		$start_time=trim(I('start_time'));
		$end_time=trim(I('end_time'));
		
		if(!empty($cate)){
			$map['cate']=$cate;
		}

		!empty($start_time)?$start_time = strtotime($start_time):$start_time=0;
		!empty($end_time)?$end_time = strtotime($end_time):$end_time =time();
		if(date("Y-m-d",$end_time)==date("Y-m-d",time())){
			$end_time=date("Y-m-d",$end_time).' 23:59:59';
			$end_time=strtotime($end_time);
		}
		$map['_string'] = "update_time>=$start_time AND update_time<=$end_time";
		
		$m_list=$m->where($map)->order('update_time desc,cate')->select();
		// echo $m->getlastsql();
		$count=$m->where($map)->count();

		foreach($m_list as $ks=>$vs){
			$m_list[$ks]['update_time']=date("Y-m-d H:i:s",$vs['update_time']);
		}
		if(!empty($m_list)){
            $data['total']=$count;
            $data['rows']=$m_list;
        }else{
            $data['total']=0;
            $data['rows']=0;
        }
		
        $this->ajaxReturn($data);
	}
	public function make_statistical_storage(){
		$p=M('Packing',C('DB_PRS'),C('DB_DEPOT'));
		$s=M('StorageOutbound',C('DB_PRS'),C('DB_DEPOT'));
		$m=M('StatisticalStorage',C('DB_PRS'),C('DB_DEPOT'));
		
		$time=I('time');
		if(empty($time)){
			$time=time();//统计时间
		}else{
			$time=strtotime($time);//转成时间戳
		}
		
		//出库-begin
		$time_today=date("Y-m-d",$time);//今天
		$time_nextday=date("Y-m-d",$time+3600*24);//明天
		$str_time_today=strtotime($time_today);
		$str_time_nextday=strtotime($time_nextday);
		$map_s['_string']="add_time>$str_time_today and add_time<$str_time_nextday";
		$map_s['out_cate']=1;//订单出库
		$s_info=$s->field("count(*) counts")->where($map_s)->select();

		$data_s['cate']=1;//出库
		$data_s['count']=$s_info[0]['counts'];
		$data_s['update_time']=$time;
		$map_m["_string"]="DATE(FROM_UNIXTIME(`update_time`))='$time_today'";
		$map_m['cate']=1;
		$m_info=$m->where($map_m)->find();

		if(!empty($m_info)){
			$m->where($map_m)->save($data_s);
		}else{
			$m->add($data_s);
		}
		//出库-end
		
		//打包-begin
		$map_p["_string"]="DATE_FORMAT(created_at,'%Y-%m-%d')='$time_today'";
		$p_count=$p->where($map_p)->count();

		$data_p['cate']=2;//打包
		$data_p['count']=$p_count;
		$data_p['update_time']=$time;
		$map_m['cate']=2;
		$m_info=$m->where($map_m)->find();
		if(!empty($m_info)){
			$m->where($map_m)->save($data_p);
		}else{
			$m->add($data_p);
		}
		//打包-end
		
		//称重-begin
		$map_p['pack_weight']=array('exp','is not null');
		$p_count=$p->where($map_p)->count();
		$data_p['cate']=3;//称重
		$data_p['count']=$p_count;
		$data_p['update_time']=$time;
		$map_m['cate']=3;
		$m_info=$m->where($map_m)->find();
		if(!empty($m_info)){
			$m->where($map_m)->save($data_p);
		}else{
			$m->add($data_p);
		}
		//称重-end
	}
	public function get_picklist_printorder(){
		$m=M('Picklist',C('DB_PRS'),C('DB_DEPOT'));
		$n=M('Pickorder',C('DB_PRS'),C('DB_DEPOT'));
		$p=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));

		$id=I('picklist_id');
		$picklist_info=$m->where(array('id'=>$id))->find();
		// echo $m->getlastsql();
		$pickorder_list=$n->where(array('picklist_no'=>$picklist_info['picklist_no']))->select();
		// echo $n->getlastsql();
		// dump($pickorder_list);
		$arr=array();
		foreach($pickorder_list as $k=>$v){
			$arr[]=$v['order_id'];
		}
		// dump($arr);
		$info=$p->where(array('id'=>array('in',$arr)))->select();
		// dump($info);
		// echo $p->getlastsql();
		foreach($info as $ks=>$vs){
			$info[$ks]['add_time']=date("Y-m-d",$vs['add_time']);
		}
		if(!empty($info)){
            $data['total']=count($info);
            $data['rows']=$info;
        }else{
            $data['total']=0;
            $data['rows']=0;
        }
		
        $this->ajaxReturn($data);
	}
	
	//获取面单列表数据(一般订单)
	public function get_printorder(){
		$m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$n=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
		$model=M('',C('DB_PRS'),C('DB_DEPOT'));
        $ck=A('CheckInput');
		
        //搜索条件
        $map=array();
		$is_emergency=I('is_emergency');
		if($is_emergency==1){//紧急订单
			$map['status']=1;
			$map['is_emergency']=1;
		}
		// $map['pick_status']=0;//未生成波次单
		//拦截
		$inter_list=$this->zintercepted();//拦截订单列表
		$cc=count($inter_list);//拦截订单数量
		if($cc){ //cc大于0，则说明有拦截订单
			foreach($inter_list as $key=>$val){
				$arr[$key]=$val['order_no'];
			}
			$map['order_no']=array('not in',$arr); //移除拦截订单
		}
		$first_orderid=I('first_orderid','',trim);
		
		$order_no=I('order_no','',trim);
		$mailNo=I('mailNo','',trim);
		$receiveMan=I('receiveMan','',trim);
		$print_status=I('print_status','',trim);
		$start_time=I('start_time','',trim);
		$end_time=I('end_time','',trim);
		$ems_code=I('ems_code','',trim);
		
		$logiscompany_name=I('logiscompany_name','',trim);
		
		if(!empty($logiscompany_name)){
			$map['logiscompany_name']=array('like',"%".$logiscompany_name."%");
		}
		// $showall=I('showall','',trim);
		$pick_status=I('pick_status','',trim);
		if($pick_status==2){//未拣货
			$map['pick_status']=0;
		}
		if($pick_status==1){//已拣货
			$map['pick_status']=1;
		}
		$is_delivery=I('is_delivery','',trim);
		if($is_delivery==2){//未出库
			$map['is_delivery']=0;
		}
		if($is_delivery==1){//已出库
			$map['is_delivery']=1;
		}
		
        $goods_name=I('goods_name','',trim);
		$number=I('nums','',trim);
		$radio_pick=I('check_cate');
		$map['transport_cate']=array('not in','1,3');//非自提、送货的销售单和所有的一般订单（1：自提订单2：第三方物流订单3：送货订单）
		// $map['order_cate']=1;
		!empty($order_no)?$map['order_no']=array('like','%'.$order_no.'%'):'';
        !empty($mailNo)?$map['logistics_no']=array('like','%'.$mailNo.'%'):'';
		!empty($receiveMan)?$map['user_name']=array('like','%'.$receiveMan.'%'):'';
		!empty($start_time)?$start_time = strtotime($start_time):$start_time=0;
		!empty($end_time)?$end_time = strtotime($end_time):$end_time =time();
		!empty($ems_code)?$map['logistics_business']=$ems_code:'';
		$map['_string'] = "add_time>=$start_time AND add_time<=$end_time";
		
		if(!empty($first_orderid)){
			$map['o.id']=array('elt',$first_orderid);
		}
		
		if($print_status==1){
			$map['times']=0;
		}
		if($print_status==2){
			$map['times']=array('GT',0);
		}
		
		$company_name=I('company_name','',trim);
		
		if(!empty($company_name)){
			$map['company_name']=array('like',"%$company_name%");
		}
		
        $page=$ck->in('当前页','page','intval','1',0,0);   
        $rows=$ck->in('每页记录数','rows','intval','',0,0);  

        //排序
        $sort=$ck->in('排序','sort','cnennumstr','id',0,0);
        $order=$ck->in('规则','order','cnennumstr','desc',0,0);
        
		if($radio_pick==1){ //完全匹配（唯一）
			if($number==''){
				$error_text="数量不能为空";
				alert_json(0,$error_text);
			}
			$map['goods_nums']=$number;
			//生成子查询sql语句
			$sql=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('o.pick_status,g.order_id,g.goods_nums,g.goods_name,o.logiscompany_name,o.province,o.city,o.area,o.id,o.order_no,o.logistics_no,o.times,o.add_time,o.user_idcard,o.user_name,o.user_phone,o.user_address')->where($map)->buildSql();
			$list_count=$model->table($sql.' a')->group('order_id')->having("count(order_id)=1 and goods_name='$goods_name'")->select();
			$count=count($list_count);
			$info=$model->table($sql.' a')->group('order_id')->having("count(order_id)=1 and goods_name='$goods_name'")->page($page,$rows)->order($sort.' '.$order)->select();
			
		}
		if($radio_pick==5){ //商品唯一但不匹配此商品数量
			if($number==''){
				$error_text="数量不能为空";
				alert_json(0,$error_text);
			}
			$map['goods_nums']=array('neq',$number);
			//生成子查询sql语句
			$sql=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('o.pick_status,g.order_id,g.goods_nums,g.goods_name,o.logiscompany_name,o.province,o.city,o.area,o.id,o.order_no,o.logistics_no,o.times,o.add_time,o.user_idcard,o.user_name,o.user_phone,o.user_address')->where($map)->buildSql();
			$list_count=$model->table($sql.' a')->group('order_id')->having("count(order_id)=1 and goods_name='$goods_name'")->select();
			$count=count($list_count);
			$info=$model->table($sql.' a')->group('order_id')->having("count(order_id)=1 and goods_name='$goods_name'")->page($page,$rows)->order($sort.' '.$order)->select();
		}

		if($radio_pick==2){ //包含此商品并且匹配此商品数量
			if($number==''){
				$error_text="数量不能为空";
				alert_json(0,$error_text);
			}
			$map['goods_nums']=$number;
			//生成子查询sql语句
			$sql=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('o.pick_status,g.order_id,g.goods_nums,g.goods_name,o.logiscompany_name,o.province,o.city,o.area,o.id,o.order_no,o.logistics_no,o.times,o.add_time,o.user_idcard,o.user_name,o.user_phone,o.user_address')->where($map)->buildSql();
			$list_count=$model->table($sql.' a')->group('order_id')->having("count(order_id)<>1 and goods_name='$goods_name'")->select();
			$count=count($list_count);
			$info=$model->table($sql.' a')->group('order_id')->having("count(order_id)<>1 and goods_name='$goods_name'")->page($page,$rows)->order($sort.' '.$order)->select();
			// echo $model->getlastsql();
			// die;
		}
		if($radio_pick==3){ //包含此商品但不匹配此商品数量
			if($number==''){
				$error_text="数量不能为空";
				alert_json(0,$error_text);
			}
			$map['goods_nums']=array('neq',$number);
			//生成子查询sql语句
			$sql=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('o.pick_status,g.order_id,g.goods_nums,g.goods_name,o.logiscompany_name,o.province,o.city,o.area,o.id,o.order_no,o.logistics_no,o.times,o.add_time,o.user_idcard,o.user_name,o.user_phone,o.user_address')->where($map)->buildSql();
			$list_count=$model->table($sql.' a')->group('order_id')->having("count(order_id)<>1 and goods_name='$goods_name'")->select();
			$count=count($list_count);
			$info=$model->table($sql.' a')->group('order_id')->having("count(order_id)<>1 and goods_name='$goods_name'")->page($page,$rows)->order($sort.' '.$order)->select();
		}
		if($radio_pick==4){ //不包含此商品
			$map['goods_name']=array('neq',$goods_name);
			$list_count=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('o.pick_status,g.order_id,g.goods_nums,o.logiscompany_name,o.province,o.city,o.area,o.id,o.order_no,o.logistics_no,o.times,o.add_time,o.user_idcard,o.user_name,o.user_phone,o.user_address')->where($map)->select();
			$count=count($list_count);
			$info=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('o.pick_status,g.order_id,g.goods_nums,o.logiscompany_name,o.province,o.city,o.area,o.id,o.order_no,o.logistics_no,o.times,o.add_time,o.user_idcard,o.user_name,o.user_phone,o.user_address')->where($map)->page($page,$rows)->order($sort.' '.$order)->select();
			
		}
		if($radio_pick==0){
			$count=$m->alias('o')->where($map)->count();
			
			if(empty($map)){
				$info=$m->alias('o')->page($page,$rows)->order($sort.' '.$order)->select();
			}else{
				$info=$m->alias('o')->where($map)->page($page,$rows)->order($sort.' '.$order)->select();
			}
		}
		// echo $m->getlastsql();
		// echo $n->getlastsql();
		//导出Excel
		$excel=I('excel');
		// echo $p->getlastsql();
		// dump($logiscompany_name);
		// die;
		$show_advance=I('show_advance');//显示隐藏信息
        foreach($info as $k=>$v){
			// $order_info=$p->where(array('order_no'=>$v['order_no']))->find();//取出订单信息
			// echo $p->getlastsql();
			$goods_list=$n->field("goods_no,goods_name,goods_nums")->where(array('order_id'=>$v['id']))->select();//取出订单详情商品信息
			// echo $n->getlastsql();
			// dump($goods_list);
			// die;
			$info[$k]['goods_list']=$goods_list;
			
			if(!$show_advance){
				$info[$k]['user_name']=cut_str($v['user_name'],1,0).'**';
				$info[$k]['user_phone']=substr($v['user_phone'],0,7).'****';
				$info[$k]['user_idcard']=strlen(trim($v['user_idcard']))==0?'无':(strlen(trim($v['user_idcard']))==15?substr_replace(trim($v['user_idcard']),"****",8,4):(strlen(trim($v['user_idcard']))==18?substr_replace(trim($v['user_idcard']),"****",10,4):"身份证位数错误！"));
			}
			if(!empty($excel)){ //导出Excel
				$info[$k]['logistics_no']="'".$v['logistics_no'];//转字符串
				$info[$k]['user_phone']="'".$v['user_phone'];//转字符串
				$goods_no="";
				$goods_name="";
				$goods_nums="";
				foreach($goods_list as $keyss=>$valuess){
					if($keyss){
						$goods_no.='/'.$valuess['goods_no'];
					}else{
						$goods_no.="'".$valuess['goods_no'];
					}
					if($keyss){
						$goods_name.='/'.$valuess['goods_name'];
					}else{
						$goods_name.=$valuess['goods_name'];
					}
					if($keyss){
						$goods_nums.='/'.$valuess['goods_nums'];
					}else{
						$goods_nums.=$valuess['goods_nums'];
					}
				}
				$info[$k]['goods_no']=$goods_no;//商品编码
				$info[$k]['goods_name']=$goods_name;//商品名称
				$info[$k]['goods_nums']=$goods_nums;//商品数量
			}
			if(!empty($v['add_time'])){
				$info[$k]['add_time']=date("Y-m-d H:i:s",$v['add_time']);
			}
		}
		if(!empty($excel)){ //导出Excel
			$xlsName  = "面单管理";
			$xlsCell  = array(
				array('id','ID'),
				array('order_no','订单编号'),
				array('logistics_no','电子面单号'),
				array('user_name','收件人姓名'),
				array('user_phone','收件人电话'),
				array('province','省'),
				array('city','市'),
				array('area','区'),
				array('user_address','收件人地址'),
				array('times','打印次数'),
				array('add_time','推送时间'),
				array('goods_no','商品编码'),
				array('goods_name','商品名称'),
				array('goods_nums','商品数量')
			);
			exportExcel($xlsName,$xlsCell,$info);
			die;
		}
		
		if(empty($first_orderid)){
			$first_orderid=$info[0]['id'];
		}
		// dump(I());
        if(!empty($info)){
            $data['total']=$count;
            $data['rows']=$info;
			$data['first_orderid']=$first_orderid;
        }else{
            $data['total']=0;
            $data['rows']=0;
        }
		
        $this->ajaxReturn($data);
    }
    //冻结记录
    public function get_freezlog(){
        $p=M('FreezLog',C('DB_PRS'),C('DB_DEPOT'));
        //$g=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
        $param=I('param.','','trim');
        $map=array();
        //$map['is_delivery']=1;
        if(empty($param['start_time'])){
            $start_time=strtotime(0);
        }else{
            $start_time=strtotime($param['start_time']);
        }
        if(empty($param['end_time'])){
            $end_time=time();
        }else{
            $end_time=strtotime($param['end_time']);
        }
		if(!empty($param['source_no'])){
            $map['g.source_no']=$param['source_no'];
        }
        if(!empty($param['goods_no'])){
            $goods_no=$param['goods_no'];
            $map['g.goods_no']=array('like',"%$goods_no%");
        }

        $map['p.time']=array(array('gt',$start_time),array('lt',$end_time));
        //导出Excel
        $excel=I('excel');

        $page=empty($param['page'])?'1':$param['page'];
        $rows=empty($param['rows'])?'15':$param['rows'];
        //排序
        $sort=empty($param['sort'])?'id':$param['sort'];
        $order=empty($param['order'])?'desc':$param['order'];

        if(!empty($excel)){ //导出Excel
            $list=$p->alias('p')->field('p.order_no,p.logistics_no,g.goods_no,g.goods_name,g.goods_price,g.goods_nums,from_unixtime(p.delivery_time) delivery_time,from_unixtime(p.push_outboundtime) push_outboundtime')->join("__PUSHORDERGOODS__ g on p.id=g.order_id")->where($map)->order('p.id desc')->select();
        }else{
            $list=$p->alias('p')->field('p.time,p.goods_no,p.freez_amount,p.storage_amount,p.goods_id,p.times')/*->join("__PUSHORDERGOODS__ g on p.id=g.order_id")*/->where($map)->page($page,$rows)->order('p.'.$sort.' '.$order)->select();
        }
        foreach ($list as $v=>$val){
            $list[$v]['time'] = date('Y-m-d H:i:s',$val['time']);
        }
        $count=$p->alias('p')/*->join("__PUSHORDERGOODS__ g on p.id=g.order_id")*/->where($map)->count();

        if(!empty($excel)){ //导出Excel
            // $xlsName  = "出库明细";
            // $xlsCell  = array(
            // array('order_no','订单号'),
            // array('logistics_no','运单号'),
            // array('goods_no','商品编码'),
            // array('goods_name','商品名称'),
            // array('goods_price','单价'),
            // array('goods_nums','数量'),
            // array('delivery_time','出库时间'),
            // array('push_outboundtime','申报时间')
            // );
            // exportExcel($xlsName,$xlsCell,$list);
            $this->export_deliver_csv($list);
            die;
        }

        if(!empty($list)){
            $data['total']=$count;
            $data['rows']=$list;
        }else{
            $data['total']=0;
            $data['rows']=0;
        }
        $this->ajaxReturn($data);
    }
	//出库明细
	public function get_deliverlog(){
		$p=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$g=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
		$param=I('param.','','trim');
		$map=array();
		$map['is_delivery']=1;
		if(empty($param['start_time'])){
			$start_time=strtotime(0);
		}else{
			$start_time=strtotime($param['start_time']);
		}
		if(empty($param['end_time'])){
			$end_time=time();
		}else{
			$end_time=strtotime($param['end_time']);
		}
		if(!empty($param['order_no'])){
			$order_no=$param['order_no'];
			$map['p.order_no']=array('like',"%$order_no%");
		}
		if(!empty($param['goods_no'])){
			$goods_no=$param['goods_no'];
			$map['g.goods_no']=array('like',"%$goods_no%");
		}
		if(!empty($param['push_outboundstatus'])){
			$push_outboundstatus=$param['push_outboundstatus'];
			if($push_outboundstatus==1){
				$map['p.push_outboundstatus']=1;
			}
			if($push_outboundstatus==2){
				$map['p.push_outboundstatus']=0;
			}
		}
		$map['p.delivery_time']=array(array('gt',$start_time),array('lt',$end_time));
		//导出Excel
		$excel=I('excel');
		
		$page=empty($param['page'])?'1':$param['page'];
        $rows=empty($param['rows'])?'15':$param['rows'];
        //排序
        $sort=empty($param['sort'])?'id':$param['sort'];
        $order=empty($param['order'])?'desc':$param['order'];
		
		if(!empty($excel)){ //导出Excel
			$list=$p->alias('p')->field('p.order_no,p.logistics_no,g.goods_no,g.goods_name,g.goods_price,g.goods_nums,from_unixtime(p.delivery_time) delivery_time,from_unixtime(p.push_outboundtime) push_outboundtime')->join("__PUSHORDERGOODS__ g on p.id=g.order_id")->where($map)->order('p.id desc')->select();
		}else{
			$list=$p->alias('p')->field('p.order_no,p.logistics_no,g.goods_no,g.goods_name,g.goods_price,g.goods_nums,from_unixtime(p.delivery_time) delivery_time,from_unixtime(p.push_outboundtime) push_outboundtime')->join("__PUSHORDERGOODS__ g on p.id=g.order_id")->where($map)->page($page,$rows)->order('p.'.$sort.' '.$order)->select();
		}

		$count=$p->alias('p')->join("__PUSHORDERGOODS__ g on p.id=g.order_id")->where($map)->count();

		if(!empty($excel)){ //导出Excel
			// $xlsName  = "出库明细";
			// $xlsCell  = array(
				// array('order_no','订单号'),
				// array('logistics_no','运单号'),
				// array('goods_no','商品编码'),
				// array('goods_name','商品名称'),
				// array('goods_price','单价'),
				// array('goods_nums','数量'),
				// array('delivery_time','出库时间'),
				// array('push_outboundtime','申报时间')
			// );
			// exportExcel($xlsName,$xlsCell,$list);
			$this->export_deliver_csv($list);
			die;
		}
		
		if(!empty($list)){
            $data['total']=$count;
            $data['rows']=$list;
        }else{
            $data['total']=0;
            $data['rows']=0;
        }
        $this->ajaxReturn($data);
	}
	//导出出库明细csv
	public function export_deliver_csv($data){
		$header = "订单号, 运单号,商品编码,商品名称,单价,数量,出库时间,申报时间\n";
		// $header = iconv('GB2312', 'UTF-8', $header); ////将字符串的编码从GB2312转到UTF-8
		foreach($data as $k=>$row){
			$order_no		=" ".$row['order_no'];
			$logistics_no	="'".$row['logistics_no'];
			$goods_no		=" ".$row['goods_no'];
			$goods_name		=" ".str_replace("\n","",$row['goods_name']);
			$goods_price	=" ".$row['goods_price'];
			$goods_nums		=" ".$row['goods_nums'];
			$delivery_time	=" ".$row['delivery_time'];
			$push_outboundtime	=" ".$row['push_outboundtime'];
			$header .= $order_no.",".$logistics_no.",".$goods_no.",".$goods_name.",".$goods_price.",".$goods_nums.",".$delivery_time.",".$push_outboundtime."\n"; //用引文逗号分开 
		}
		$filename = "出库明细".date('YmdHis').'.csv'; //设置文件名 
		$this->download_csv($filename,$header); //导出 
	}
	public function download_csv($filename,$data) { 
        header("Content-type:text/csv"); 
        header("Content-Disposition:attachment;filename=".$filename); 
        header('Cache-Control:must-revalidate,post-check=0,pre-check=0'); 
        header('Expires:0'); 
        header('Pragma:public'); 
        echo $data; 
    }

	public function deliver_log(){
		$this->display();
	}
	//出库
	public function outbound_order(){
		$m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$id=I('id');
		$arr=explode(',',$id);
		$map['id']=array('in',$arr);
		$data['is_delivery']=1;
		$status=$m->where($map)->save($data);
		if($status!==false){
			$return['status']=true;
			$return['message']='出库成功';
			$this->ajaxReturn($return);
		}else{
			$return['status']=false;
			$return['message']='出库失败';
			$this->ajaxReturn($return);
		}
	}
	//备注同步erp
	public function pusherp($id){
		$m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$data=$m->field('logistics_no,mark_mailno,erp_code')->where(array('id'=>$id))->find();
		$url=C('BASE_CONFIG.pusherp_mark');
		$push=A('Pushsendapi');
		$res=$push->push($url,$data);
		if($res){
			alert_json(1,'成功!');
		}else{
			alert_json(0,'同步出错!');
		}
	}
	//填写运单号
	public function pushorderSave(){
		$m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$param=I('param.','','trim');
		$map['id']=$param['id'];
		// $data['logistics_no']=$param['logistics_no'];
		$data['mark_mailno']=$param['mark_mailno'];
		$status=$m->where($map)->save($data);
		if($status!==false){
			$this->pusherp($param['id']);
			$return['status']=true;
			$return['message']='成功';
			$this->ajaxReturn($return);
		}else{
			$return['status']=false;
			$return['message']='失败';
			$this->ajaxReturn($return);
		}
	}
	//推送出库信息(一般仓)
	public function pushoms_outstatus($logistics_no){
		$url=C('BASE_CONFIG.get_methodbatch');//更新出库信息(出库申报同一个接口)

		$arr=array();
		$arr[0]['logistics_no']=$logistics_no;
		$arr[0]['pack_weight']=0.1;
		$arr[0]['merchant_code']='C3525019680';
			
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

		//post传值数据
		curl_setopt($ch, CURLOPT_POST, 1);
		//post的变量
		curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('data'=>$arr)));
		$output = curl_exec($ch);
		curl_close($ch);
		$res= json_decode($output,true);

		if($res['flag']){//成功
		}else{//失败
			$return['status']=0;
			$return['message']='出库成功！OMS回执:'.$res['tip'];
			$this->ajaxReturn($return);
		}
	}
	//推送出库信息(跨境推送出库状态)--弃用
	public function pushoms_outstatus_cross($logistics_no){
		$url=C('BASE_CONFIG.delivery_out');//更新出库信息(出库申报同一个接口)
		
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

		//post传值数据
		curl_setopt($ch, CURLOPT_POST, 1);
		//post的变量
		curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('logistics_no'=>$logistics_no)));
		$output = curl_exec($ch);
		curl_close($ch);
		$res= json_decode($output,true);

		if($res['flag']){//成功
		}else{//失败
			$return['status']=0;
			$return['message']='出库成功！OMS回执:'.$res['tip'];
			$this->ajaxReturn($return);
		}
	}
	//批量出库（运单号）
	public function outbount_batch(){
		$trans = M('',C('DB_PRS'),C('DB_DEPOT'));
		$trans->startTrans();   // 开启事务
		$mailNo=I('mailNo','','trim');
		$mailNo_list=explode(',',$mailNo);
		foreach($mailNo_list as $k=>$v){
			$res=$this->outbound_order_mailNo($v);
			if(!$res['status']){
				$trans->rollback();
				$this->ajaxReturn($res);
				die;
			}
		}
		$trans->commit();
		$return['status']=true;
		$return['message']='成功';
		$this->ajaxReturn($return);
	}
	//出库2（运单号）
	public function outbound_order_mailNo($mailNo){
		$so=M('StorageOutbound',C('DB_PRS'),C('DB_DEPOT'));//出库记录表
		$ao=M('ArrivalOrder',C('DB_PRS'),C('DB_DEPOT'));
		$m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$mg=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
		
		$P=M("Packing",C('DB_PRS'),C('DB_DEPOT'));
		
		$warehouse=M('Warehouse');
		$map['logistics_no']=$mailNo;
		$data['is_delivery']=1;
		$data['delivery_time']=time();
		$info=$m->where($map)->find();
		
		$counts=$m->where($map)->count();
		if($counts>1){
			$return['status']=false;
			$return['message']='运单号重复，请确认后删除重复订单！';
			$this->ajaxReturn($return);
		}
		
		if(empty($info)){
			$return['mailNo']=$mailNo;
			$return['status']=false;
			$return['message']='没有查到此运单';
			return $return;
		}else{
			$this->emergency_order($mailNo);
			// echo $m->getlastsql();
			if($P->where("order_no='{$info['order_no']}' and pack_weight is not null")->count()<=0){
				$return['mailNo']=$mailNo;
				$return['status']=false;
				$return['message']='此面单未称重，不能出库';
				return $return;
			}
				
			
				if($info['is_delivery']==1){
					$return['mailNo']=$mailNo;
					$return['status']=false;
					$return['message']='已出过库,不能再次出库！';
					return $return;
				}else{
					$status=$m->where($map)->save($data);
					if($status!==false){
						///////////////////////////////更新批次库存begin
						$info_goods=$mg->where(array('order_id'=>$info['id']))->select();
						foreach($info_goods as $k=>$v){
							$goods_batch_no=explode(',',$v['goods_batch_no']);
							$goods_batch_no=array_filter($goods_batch_no);//去空
							foreach($goods_batch_no as $ks=>$vs){
								$arr=explode(':',$vs);
								$map_ao['id']=$arr[0];
								$data_ao['freez_amount']=array('exp','freez_amount-'.$arr[1]);
								$ao->where($map_ao)->save($data_ao);//更新批次库存表
								$so->add(array('outbound_order_id'=>$info['id'],'inbound_order_id'=>$arr[0],'nums'=>$arr[1],'add_time'=>time(),'out_cate'=>1));//更新出库记录out_cate:(出库类型1:订单出库2:异常出库3:销售单出库数量4:调拨出库5:领料出库)
							}
						}
						/////////////////////////////更新批次库存end
						$warehouse_code=session('warehouse_code');
						$warehouse_cate=$warehouse->where(array('warehouse_code'=>$warehouse_code))->getField('warehouse_cate');

						if($warehouse_cate==1){//一般仓
							$this->pushoms_outstatus($mailNo);//推送出库信息
						}
						$return['mailNo']=$mailNo;
						$return['status']=true;
						$return['message']='出库成功';
						return $return;
					}else{
						$return['mailNo']=$mailNo;
						$return['status']=false;
						$return['message']='出库失败';
						return $return;
					}
				}
			
		}
	}
	public function emergency_order($mailNo){
		$m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$n=M('NuclearOrder',C('DB_PRS'),C('DB_DEPOT'));
		$map['logistics_no']=$mailNo;
		$map['status']=1;
		$is_emergency=$m->where($map)->getField('is_emergency');
		if($is_emergency==1){//紧急订单
			//验证核放单
			$map_n['mail_no']=$mailNo;
			$n_info=$n->where($map_n)->find();
			if(empty($n_info)){
				$return['mailNo']=$mailNo;
				$return['status']=4;
				$return['message']='此运单未放行，不能出库';
				$this->ajaxReturn($return);
			}
		}
	}
	//出库2（运单号）
	public function outbound_order2(){
		$so=M('StorageOutbound',C('DB_PRS'),C('DB_DEPOT'));//出库记录表
		$ao=M('ArrivalOrder',C('DB_PRS'),C('DB_DEPOT'));
		$m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$mg=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
		
		$P=M("Packing",C('DB_PRS'),C('DB_DEPOT'));
		
		$warehouse=M('Warehouse');
		$mailNo=I('mailNo');
		$map['logistics_no']=$mailNo;
		$data['is_delivery']=1;
		$data['delivery_time']=time();
		$info=$m->where($map)->find();

		
		$counts=$m->where($map)->count();
		if($counts>1){
			$return['status']=5;
			$return['message']='运单号重复，请确认后删除重复订单！';
			$this->ajaxReturn($return);
		}
		if(empty($info)){
			$return['status']=6;
			$return['message']='没有查到此运单';
			$this->ajaxReturn($return);
		}else{
			$this->emergency_order($mailNo);
			// echo $m->getlastsql();
			if($P->where("order_no='{$info['order_no']}' and pack_weight is not null")->count()<=0){
				$return['status']=2;
				$return['message']='此面单未称重，不能出库';
				$this->ajaxReturn($return);
			}
				
			
			if($info['is_delivery']==1){
				$return['status']=3;
				$return['message']='已出过库,不能再次出库！';
				$this->ajaxReturn($return);
			}else{
				$status=$m->where($map)->save($data);
				if($status!==false){
					///////////////////////////////更新批次库存begin
					$info_goods=$mg->where(array('order_id'=>$info['id']))->select();
					foreach($info_goods as $k=>$v){
						$goods_batch_no=explode(',',$v['goods_batch_no']);
						$goods_batch_no=array_filter($goods_batch_no);//去空
						foreach($goods_batch_no as $ks=>$vs){
							$arr=explode(':',$vs);
							$map_ao['id']=$arr[0];
							$data_ao['freez_amount']=array('exp','freez_amount-'.$arr[1]);
							$ao->where($map_ao)->save($data_ao);//更新批次库存表
							$so->add(array('outbound_order_id'=>$info['id'],'inbound_order_id'=>$arr[0],'nums'=>$arr[1],'add_time'=>time(),'out_cate'=>1));//更新出库记录out_cate:(出库类型1:订单出库2:异常出库3:销售单出库数量4:调拨出库5:领料出库)
						}
					}
					/////////////////////////////更新批次库存end
					$warehouse_code=session('warehouse_code');
					$warehouse_cate=$warehouse->where(array('warehouse_code'=>$warehouse_code))->getField('warehouse_cate');

					if($warehouse_cate==1){//一般仓
						$this->pushoms_outstatus($mailNo);//推送出库信息
					}
					$return['status']=true;
					$return['message']='出库成功';
					$return['order_no']=$mailNo;
					$this->ajaxReturn($return);
				}else{
					$return['status']=false;
					$return['message']='出库失败';
					$this->ajaxReturn($return);
				}
			}
		}
	}
	//自提出库（订单号）
	public function outbound_order_own(){
		$so=M('StorageOutbound',C('DB_PRS'),C('DB_DEPOT'));//出库记录表
		$ao=M('ArrivalOrder',C('DB_PRS'),C('DB_DEPOT'));
		$m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$mg=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
		$warehouse=M('Warehouse');
		$order_no=I('order_no');
		$map['order_no']=$order_no;
		$data['is_delivery']=1;
		$data['delivery_time']=time();
		$info=$m->where($map)->find();
		// echo $m->getlastsql();
		if(empty($info)){
			$return['status']=false;
			$return['message']='没有查到此订单';
			$this->ajaxReturn($return);
		}else{
			// echo $m->getlastsql();
				if($info['is_delivery']==1){
					$return['status']=false;
					$return['message']='已出过库,不能再次出库！';
					$this->ajaxReturn($return);
				}else{
					$status=$m->where($map)->save($data);
					if($status!==false){
						///////////////////////////////更新批次库存begin
						$info_goods=$mg->where(array('order_id'=>$info['id']))->select();
						foreach($info_goods as $k=>$v){
							$goods_batch_no=explode(',',$v['goods_batch_no']);
							$goods_batch_no=array_filter($goods_batch_no);//去空
							foreach($goods_batch_no as $ks=>$vs){
								$arr=explode(':',$vs);
								$map_ao['id']=$arr[0];
								$data_ao['freez_amount']=array('exp','freez_amount-'.$arr[1]);
								$ao->where($map_ao)->save($data_ao);//更新批次库存表
								$so->add(array('outbound_order_id'=>$info['id'],'inbound_order_id'=>$arr[0],'nums'=>$arr[1],'add_time'=>time(),'out_cate'=>1));//更新出库记录out_cate:(出库类型1:订单出库2:异常出库3:销售单出库数量4:调拨出库5:领料出库)
							}
						}
						/////////////////////////////更新批次库存end
						$warehouse_code=session('warehouse_code');
						$warehouse_cate=$warehouse->where(array('warehouse_code'=>$warehouse_code))->getField('warehouse_cate');
						if($warehouse_cate==1){//一般仓
							$this->pushoms_outstatus($order_no);//推送出库信息
						}
						$return['status']=true;
						$return['message']='出库成功';
						$this->ajaxReturn($return);
					}else{
						$return['status']=false;
						$return['message']='出库失败';
						$this->ajaxReturn($return);
					}
				}
			
		}
	}
	//删除紧急订单
	public function del_order_emergency(){
		$m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$param=I('param.','','trim');
		$id=$param['id'];
		$map['id']=array('in',$id);
		$m_list=$m->where($map)->select();
		foreach($m_list as $k=>$v){
			if($v['is_delivery']==1){
				alert_json(0,"物流单号".$v['logistics_no']."已出库，不能删除");
				exit;
			}
		}
		$res=$m->where($map)->save(array('status'=>-1));
		if($res!==false){
			alert_json(1,"删除成功");
		}
	}
	//删除出库单
	public function pushoutboundstorage_del(){
		$m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$delorder=M('PushorderDel',C('DB_PRS'),C('DB_DEPOT'));//删单备份表
		$param=I('param.','','trim');
		$id=$param['id'];
		$map['id']=array('in',$id);
		$m_list=$m->where($map)->select();
		foreach($m_list as $k=>$v){
			if($v['push_outboundstatus']==1){
				alert_json(0,"物流单号".$v['logistics_no']."已申报，不能删除");
				exit;
			}
		}
		$sql="insert into tz_pushorder_del select * from tz_pushorder where id=$id";
		M('',C('DB_PRS'),C('DB_DEPOT'))->execute($sql);
		$res=$m->where($map)->delete();
		if($res!==false){
			alert_json(1,"删除成功");
		}
	}
	//订单列表
	public function get_orderlist(){
        $m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
        $ck=A('CheckInput');
		
        //搜索条件
        $map=array();
		// $map['times']=array('neq',0);
		$map['is_delivery']=1;
        $order_no=$ck->in('订单编码','order_no','ennumstr','',0,0);        
        $user_name=$ck->in('客户姓名','user_name','cnennumstr','',0,0);
		$user_phone=$ck->in('联系电话','user_phone','ennumstr','',0,0);
		$mailNo=$ck->in('面单号','mailNo','ennumstr','',0,0);       
		$is_delivery=1;
		// if(!empty($is_delivery)){
			// if($is_delivery==2){
				// $is_delivery=0;
			// }
			// $map['is_delivery']=$is_delivery;
		// }
        !empty($order_no)?$map['order_no']=array('like','%'.$order_no.'%'):'';
		!empty($mailNo)?$map['logistics_no']=array('like','%'.$mailNo.'%'):'';
		!empty($user_name)?$map['user_name']=array('like','%'.$user_name.'%'):'';
		!empty($user_phone)?$map['user_phone']=array('like','%'.$user_phone.'%'):'';
		
		$is_emergency=I('is_emergency','',trim);		
		if(empty($is_emergency)){
			$map['is_emergency']=0;
		}
		if($is_emergency==1){
			$map['is_emergency']=1;
		}

		$start_time=I('start_time','',trim);
		$end_time=I('end_time','',trim);
		$time_cate=I('time_cate','',trim);
		$has_push=I('has_push');
		$excel=I('excel');
		
		if($has_push==1){
			$map['push_outboundstatus']=1;
		}
		if($has_push==2){
			$map['push_outboundstatus']=0;
		}
		
		if(!empty($time_cate)){
			!empty($start_time)?$start_time = strtotime($start_time):$start_time=0;
			!empty($end_time)?$end_time = strtotime($end_time):$end_time =time();
			if($time_cate==1){
				$map['_string'] = "delivery_time>=$start_time AND delivery_time<=$end_time";//出库时间
			}
			if($time_cate==2){
				$map['_string'] = "push_outboundtime>=$start_time AND push_outboundtime<=$end_time";//申报时间
			}
		}

        $page=$ck->in('当前页','page','intval','1',0,0);   
        $rows=$ck->in('每页记录数','rows','intval','',0,0);  
		
        //排序
        $sort=$ck->in('排序','sort','cnennumstr','delivery_time',0,0);
        $order=$ck->in('规则','order','cnennumstr','desc',0,0);
        
        $count=$m->where($map)->count();
        if(empty($map)){
            $info=$m->field('id,id ids,order_no,user_name,user_phone,user_idcard,user_address,is_delivery,logistics_no,logiscompany_name,delivery_time,push_outboundstatus,push_outboundtime,push_outboundmark')->page($page,$rows)->order($sort.' '.$order)->select();
        }else{
            $info=$m->field('id,id ids,order_no,user_name,user_phone,user_idcard,user_address,is_delivery,logistics_no,logiscompany_name,delivery_time,push_outboundstatus,push_outboundtime,push_outboundmark')->where($map)->page($page,$rows)->order($sort.' '.$order)->select();
        }
		// if(!empty($excel)){
			// echo $m->getlastsql();
			// die;
		// }
		// dump($map);
		// echo $m->getlastsql();
		$show_advance=I('show_advance');//显示隐藏信息
		foreach($info as $k=>$v){
			if(!empty($v['push_outboundtime'])){
				$info[$k]['push_outboundtime']=date('Y-m-d H:i:s',$v['push_outboundtime']);
			}else{
				$info[$k]['push_outboundtime']="";
			}
			if(!empty($v['delivery_time'])){
				$info[$k]['delivery_time']=date('Y-m-d H:i:s',$v['delivery_time']);
			}else{
				$info[$k]['delivery_time']="";
			}
			if(!empty($excel)){ //导出Excel
				$info[$k]['order_no']=' '.$v['order_no'];
				$info[$k]['user_idcard']=' '.$v['user_idcard'];
				$info[$k]['user_phone']=' '.$v['user_phone'];
				$info[$k]['logistics_no']=' '.$v['logistics_no'];
			}else{
				if(!$show_advance){
					$info[$k]['user_name']=cut_str($v['user_name'],1,0).'**';
					$info[$k]['user_phone']=substr($v['user_phone'],0,7).'****';
					$info[$k]['user_idcard']=strlen(trim($v['user_idcard']))==0?'无':(strlen($v['user_idcard'])==15?substr_replace($v['user_idcard'],"****",8,4):(strlen($v['user_idcard'])==18?substr_replace($v['user_idcard'],"****",10,4):"身份证位数错误！"));
				}
			}
		}
		// echo $m->getlastsql();
		// dump($info);
		// die;
		if(!empty($excel)){ //导出Excel
			$xlsName  = "出库管理";
			$xlsCell  = array(
				array('id','ID'),
				array('order_no','订单编号'),
				array('user_name','客户姓名'),
				array('user_phone','联系电话'),
				array('user_idcard','身份证'),
				array('user_address','详细地址'),
				array('logistics_no','物流单号'),
				array('logiscompany_name','物流企业名称'),
				array('is_delivery','已出库(0:否)'),
				array('push_outboundstatus','已申报(0:否)'),
				array('delivery_time','出库时间'),
				array('push_outboundtime','申报时间')
			);
			exportExcel($xlsName,$xlsCell,$info);
			die;
		}
        if(!empty($info)){
            $data['total']=$count;
            $data['rows']=$info;
        }else{
            $data['total']=0;
            $data['rows']=0;
        }
		
        $this->ajaxReturn($data);
    }
	//自提出库订单列表
	public function get_orderlist_own(){
        $m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
        $ck=A('CheckInput');
		
        //搜索条件
        $map=array();
		// $map['times']=array('neq',0);
		// $map['is_delivery']=1;
		$map['transport_cate']=1;//运输方式：1：自提
        $order_no=$ck->in('订单编码','order_no','ennumstr','',0,0);        
        $user_name=$ck->in('客户姓名','user_name','cnennumstr','',0,0);
		$user_phone=$ck->in('联系电话','user_phone','ennumstr','',0,0);
		// $is_delivery=1;
		// if(!empty($is_delivery)){
			// if($is_delivery==2){
				// $is_delivery=0;
			// }
			// $map['is_delivery']=$is_delivery;
		// }
        !empty($order_no)?$map['order_no']=array('like','%'.$order_no.'%'):'';
		!empty($user_name)?$map['user_name']=array('like','%'.$user_name.'%'):'';
		!empty($user_phone)?$map['user_phone']=array('like','%'.$user_phone.'%'):'';

        $page=$ck->in('当前页','page','intval','1',0,0);   
        $rows=$ck->in('每页记录数','rows','intval','',0,0);  
		
        //排序
        $sort=$ck->in('排序','sort','cnennumstr','add_time',0,0);
        $order=$ck->in('规则','order','cnennumstr','desc',0,0);
        
        $count=$m->where($map)->count();
        if(empty($map)){
            $info=$m->field('id,id ids,order_no,user_name,user_phone,user_idcard,user_address,is_delivery,logistics_no,logiscompany_name,delivery_code')->page($page,$rows)->order($sort.' '.$order)->select();
        }else{
            $info=$m->field('id,id ids,order_no,user_name,user_phone,user_idcard,user_address,is_delivery,logistics_no,logiscompany_name,delivery_code')->where($map)->page($page,$rows)->order($sort.' '.$order)->select();
        }
		// echo $m->getlastsql();
		$show_advance=I('show_advance');//显示隐藏信息
		foreach($info as $k=>$v){
			
			if(!$show_advance){
				$info[$k]['user_name']=cut_str($v['user_name'],1,0).'**';
				$info[$k]['user_phone']=substr($v['user_phone'],0,7).'****';
				$info[$k]['user_idcard']=strlen(trim($v['user_idcard']))==0?'无':(strlen($v['user_idcard'])==15?substr_replace($v['user_idcard'],"****",8,4):(strlen($v['user_idcard'])==18?substr_replace($v['user_idcard'],"****",10,4):"身份证位数错误！"));
			}
		}
        if(!empty($info)){
            $data['total']=$count;
            $data['rows']=$info;
        }else{
            $data['total']=0;
            $data['rows']=0;
        }
		
        $this->ajaxReturn($data);
    }
	//核放单列表
	public function get_nuclear_order(){
		$m=M('NuclearOrder',C('DB_PRS'),C('DB_DEPOT'));
		$ck=A('CheckInput');
		$order_no=I('order_no','','trim');
		$mail_no=I('mail_no','','trim');
		$listing_no=I('listing_no','','trim');
		//搜索条件
        $map=array();
		if(!empty($listing_no)){
			$map['listing_no']=array('like',"%$listing_no%");
		}
		if(!empty($order_no)){
			$map['order_no']=array('like',"%$order_no%");
		}
		if(!empty($mail_no)){
			$map['mail_no']=array('like',"%$mail_no%");
		}

		$page=$ck->in('当前页','page','intval','1',0,0);   
        $rows=$ck->in('每页记录数','rows','intval','',0,0);
		
		//排序
		$sort=$ck->in('排序','sort','cnennumstr','id',0,0);
		$order=$ck->in('规则','order','cnennumstr','desc',0,0);
		
		$count=$m->where($map)->count();
		$list=$m->where($map)->page($page,$rows)->order($sort.' '.$order)->select();
		foreach($list as $k=>$v){
			$list[$k]['declare_time']=date('Y-m-d H:i:s',$v['declare_time']);
			$list[$k]['release_time']=date('Y-m-d H:i:s',$v['release_time']);
			$list[$k]['add_time']=date('Y-m-d H:i:s',$v['add_time']);
		}
		// echo $m->_sql();
		// die;
		
		if(!empty($list)){
            $data['total']=$count;
            $data['rows']=$list;
        }else{
            $data['total']=0;
            $data['rows']=0;
        }
        $this->ajaxReturn($data);
	}
	//未出库的紧急订单
	public function check_emergency(){
		$m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$map['status']=1;//未删除
		$map['is_delivery']=0;//未出库
		$map['is_emergency']=1;//紧急订单
		$count=$m->where($map)->count();
		if($count>0){
			alert_json(0,"存在未出库的紧急订单,请先处理完紧急订单");
			die;
		}
	}
	//订单列表(一般订单)
	public function get_order(){
        $m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$n=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
		$model=M('',C('DB_PRS'),C('DB_DEPOT'));
        $ck=A('CheckInput');
        //搜索条件
        $map=array();
		$map['pick_status']=0;//未生成波次单
		$map['is_delivery']=0;//未出库
		
		$map['transport_cate']=array('not in','1,2,3');//非自提、非第三方物流、非送货
		// $map['order_cate']=1;//一般订单
		//拦截
		$inter_list=$this->zintercepted();//拦截订单列表
		$cc=count($inter_list);//拦截订单数量
		if($cc){ //cc大于0，则说明有拦截订单
			foreach($inter_list as $key=>$val){
				$arr[$key]=$val['order_no'];
			}
			$map['order_no']=array('not in',$arr); //移除拦截订单
		}
		$goods_no=I('goods_no','',trim);
		$is_emergency=I('is_emergency','',trim);
        $goods_name=I('goods_name','',trim);
		$company_name=I('company_name','',trim);
		$number=trim(I('nums'));
		$radio_pick=I('check_cate');
		
		$logiscompany_name=I('logiscompany_name','',trim);
		$logistics_no=I('logistics_no','',trim);
		
		if(empty($is_emergency)){
			$map['is_emergency']=0;
			$this->check_emergency();
			
		}
		if($is_emergency==1){
			$map['status']=1;
			$map['is_emergency']=1;
		}
		if(!empty($logistics_no)){
			$map['logistics_no']=array('like',"%".$logistics_no."%");
		}
		if(!empty($logiscompany_name)){
			$map['logiscompany_name']=array('like',"%".$logiscompany_name."%");
		}
		if(!empty($company_name)){
			$map['company_name']=array('like',"%$company_name%");
		}
		// dump($map);
		// die;
        $page=$ck->in('当前页','page','intval','1',0,0);
        $rows=$ck->in('每页记录数','rows','intval','',0,0);
        //排序
		$sort=I('sort','',trim);
		if(empty($sort)){
			$sort="arrow_status DESC,(case logiscompany_name when '百世' then 'A' when '中通' then 'B' end) DESC,add_time";
		}else{
			$sort="arrow_status DESC,(case logiscompany_name when '百世' then 'A' when '中通' then 'B' end) DESC,".$sort;
		}
        
        $order=$ck->in('规则','order','cnennumstr','ASC',0,0);
		if($radio_pick==1){ //完全匹配（唯一）(同品单品单件)
			if($number==''){
				$error_text="数量不能为空";
				alert_json(0,$error_text);
			}
			//生成子查询sql语句
			$sql=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('g.order_id,g.goods_nums,g.goods_name,g.goods_no,o.erp_mark_mailno,o.logiscompany_name,o.province,o.city,o.area,o.id,o.order_no,o.user_idcard,o.user_name,o.user_phone,o.user_address,o.arrow_status,o.add_time')->where($map)->buildSql();
			$list_count=$model->table($sql.' a')->group('order_id')->having("count(order_id)=1 and goods_name like '%$goods_name%' and goods_nums={$number} and goods_no like '%$goods_no%'")->select();
			$count=count($list_count);
			$info=$model->table($sql.' a')->group('order_id')->having("count(order_id)=1 and goods_name like '%$goods_name%' and goods_nums={$number} and goods_no like '%$goods_no%'")->page($page,$rows)->order($sort.' '.$order)->select();
		    // echo $model->getlastsql();	
		}
		if($radio_pick==5){ //商品唯一但不匹配此商品数量(同品单品多件)
			if($number==''){
				$error_text="数量不能为空";
				alert_json(0,$error_text);
			}
			
			//生成子查询sql语句
			$sql=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('g.order_id,g.goods_nums,g.goods_name,g.goods_no,o.erp_mark_mailno,o.logiscompany_name,o.province,o.city,o.area,o.id,o.order_no,o.user_idcard,o.user_name,o.user_phone,o.user_address,o.arrow_status,o.add_time')->where($map)->buildSql();
			$list_count=$model->table($sql.' a')->group('order_id')->having("count(order_id)=1 and goods_nums>=1 and goods_name like '%$goods_name%' and goods_no like '%$goods_no%'")->select();
			$count=count($list_count);
			$info=$model->table($sql.' a')->group('order_id')->having("count(order_id)=1 and goods_nums>=1 and goods_name like '%$goods_name%' and goods_no like '%$goods_no%'")->page($page,$rows)->order($sort.' '.$order)->select();
			// echo $model->getlastsql();
		}

		if($radio_pick==2){ //包含此商品并且匹配此商品数量（）
			if($number==''){
				$error_text="数量不能为空";
				alert_json(0,$error_text);
			}
			if(empty($goods_name) && empty($goods_no)){
				alert_json(0,"请输入商品编码或商品名称");
			}

			//生成子查询sql语句
			$sql=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('g.order_id,g.goods_nums,g.goods_name,g.goods_no,o.erp_mark_mailno,o.logiscompany_name,o.province,o.city,o.area,o.id,o.order_no,o.user_idcard,o.user_name,o.user_phone,o.user_address,o.arrow_status,o.add_time')->where($map)->buildSql();

			$where_sql2['goods_no']=array('like',"%$goods_no%");
			$where_sql2['goods_name']=array('like',"%$goods_name%");
			$where_sql2['goods_nums']=$number;
			$sql2=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('g.order_id')->where($map)->where($where_sql2)->buildSql();
			
			$list_sql=$model->table($sql.' a')->group('order_id')->having("count(order_id)<>1")->buildSql();

			$list_count=$model->table($list_sql.' b')->join("INNER JOIN ($sql2) aa on b.order_id=aa.order_id")->select();
            exit(var_dump($list_count));
			$count=count($list_count);
			$info=$model->table($list_sql.' b')->join("INNER JOIN ($sql2) aa on b.order_id=aa.order_id")->page($page,$rows)->order($sort.' '.$order)->select();

			// echo $model->getlastsql();
		}
		if($radio_pick==3){ //包含此商品但不匹配此商品数量
			if($number==''){
				$error_text="数量不能为空";
				alert_json(0,$error_text);
			}
			if(empty($goods_name) || empty($goods_no)){
				alert_json(0,"请输入商品编码或商品名称");
			}

			//生成子查询sql语句
			$sql=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('g.order_id,g.goods_nums,g.goods_name,g.goods_no,o.erp_mark_mailno,o.logiscompany_name,o.province,o.city,o.area,o.id,o.order_no,o.user_idcard,o.user_name,o.user_phone,o.user_address,o.arrow_status,o.add_time')->where($map)->buildSql();
			
			$where_sql2['goods_no']=array('like',"%$goods_no%");
			$where_sql2['goods_name']=array('like',"%$goods_name%");
			$where_sql2['goods_nums'] = array('gt',1);
			$sql2=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('g.order_id')->where($map)->where($where_sql2)->buildSql();
			
			$list_sql=$model->table($sql.' a')->group('order_id')->having("count(order_id)<>1")->buildSql();
			
			$list_count=$model->table($list_sql.' b')->join("INNER JOIN ($sql2) aa on b.order_id=aa.order_id")->select();

			$count=count($list_count);
			$info=$model->table($list_sql.' b')->join("INNER JOIN ($sql2) aa on b.order_id=aa.order_id")->page($page,$rows)->order($sort.' '.$order)->select();
			
			// echo $model->getlastsql();
		}
		if($radio_pick==4){ //不包含此商品
			if(empty($goods_name) and empty($goods_no)){
				alert_json(0,"请输入商品编码或商品名称");
			}
			if(!empty($goods_name)){
				$map['goods_name']=array('notlike',"%$goods_name%");
			}
			if(!empty($goods_no)){
				$map['goods_no']=array('notlike',"%$goods_no%");
			}
			
			$list_count=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('g.order_id,g.goods_nums,o.erp_mark_mailno,o.logiscompany_name,o.province,o.city,o.area,o.id,o.order_no,o.user_idcard,o.user_name,o.user_phone,o.user_address,o.arrow_status,o.add_time')->where($map)->select();
			$count=count($list_count);
			$info=$n->alias('g')->join('__PUSHORDER__ o ON g.order_id= o.id','LEFT')->field('g.order_id,g.goods_nums,o.erp_mark_mailno,o.logiscompany_name,o.province,o.city,o.area,o.id,o.order_no,o.user_idcard,o.user_name,o.user_phone,o.user_address')->where($map)->page($page,$rows)->order($sort.' '.$order)->select();
			// echo $n->getlastsql();
		}
		
		if($radio_pick==0){
			$count=$m->where($map)->count();
			if(empty($map)){
				$info=$m->page($page,$rows)->order($sort.' '.$order)->select();
			}else{
				$info=$m->where($map)->page($page,$rows)->order($sort.' '.$order)->select();
			}
		}

		// echo $m->getlastsql();
		// die;
		$show_advance=I('show_advance');//显示隐藏信息
		foreach($info as $k=>$v){
			$goods_list=$n->field('goods_no,goods_name,goods_nums')->where(array('order_id'=>$v['id']))->select();//取出订单详情商品信息
			$info[$k]['goods_list']=$goods_list;
			
			$s=M('Storage',C('DB_PRS'),C('DB_DEPOT'));
			$storage_info=$s->where(array('storage_code'=>$v['storage_code']))->find();
			$info[$k]['storage_code']=$storage_info['name'];
			
			if(!$show_advance){
				$info[$k]['user_name']=cut_str($v['user_name'],1,0).'**';
				$info[$k]['user_phone']=substr($v['user_phone'],0,7).'****';
				$info[$k]['user_idcard']=strlen(trim($v['user_idcard']))==0?'无':(strlen($v['user_idcard'])==15?substr_replace($v['user_idcard'],"****",8,4):(strlen($v['user_idcard'])==18?substr_replace($v['user_idcard'],"****",10,4):"身份证位数错误！"));
			}
			$info[$k]['add_time']=date("Y-m-d H:i:s",$v['add_time']);
			if($v['grounding_status']==0){
				$info[$k]['grounding_status']='否';
			}
			if($v['grounding_status']==1){
				$info[$k]['grounding_status']='是';
			}
		}
        if(!empty($info)){
            $data['total']=$count;
            $data['rows']=$info;
        }else{
            $data['total']=0;
            $data['rows']=0;
        }
        $this->ajaxReturn($data);
    }
	
	//拣货单商品汇总
	public function pickcollect(){
		$this->display();
	}
	//生成拣货单汇总商品数据
	public function make_pickcollect(){
		$m=M('Pickcollect',C('DB_PRS'),C('DB_DEPOT'));
		$n=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$k=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
		$ao=M('ArrivalOrder',C('DB_PRS'),C('DB_DEPOT'));
		
		$sql = 'truncate table '.C('DB_DEPOT.DB_NAME').'.'.C('DB_PRS').'pickcollect';
		$stat=M()->execute($sql);//清空汇总表

		$id=I('id');
		$map['order_id']  = array('in',$id);
		$maps['id']  = array('in',$id);
		
		$ordernolist=$n->field('order_no,pick_status,is_delivery')->where($maps)->select();
		
		foreach($ordernolist as $key=>$value){
			if($value['pick_status']==1 or $value['is_delivery']==1){//校检
				$return['message']="订单".$value['order_no']."已生成过波次单或已出库,不能再次生成!";
				$return['status']=false;
				$this->ajaxReturn($return);
			}
			if(!$key){
				$orderlist=$orderlist.$value['order_no'];
			}else{
				$orderlist=$orderlist.'/'.$value['order_no'];
			}
		}

		$list=$k->field('goods_no,goods_name,sum(goods_nums) goods_count')->group('goods_no')->where($map)->select();
		// echo $k->getlastsql();
		foreach($list as $keys=>$v){
			$data['goods_no']	=$v['goods_no'];
			$data['goods_name']	=$v['goods_name'];
			$data['goods_count']=$v['goods_count'];
			$rule_freez=C('base_config.rule_freez');
			if($rule_freez){
			    $orderby="overdue_time";
            }else{
			    $orderby="add_time";
            }
			$ao_list=$ao->field('storage_code')->where(array('goods_no'=>$v['goods_no'],'grounding_status'=>1))->order($orderby.' desc')->select();

			// echo $ao->getlastsql();已上架并且库存大于0
			$data['storage_code']	=$ao_list[0]['storage_code'];
			$data['storage_level']	=10;
			$status=$m->add($data);
			
			if(!$status){
				$return['message']="生成出错";
				$return['status']=false;
				$this->ajaxReturn($return);
				exit;
			}
		}
		$return['message']="生成成功";
		$return['orderlist']=$orderlist;
		$return['status']=true;
		
		$this->ajaxReturn($return);
	}
	//拣货单商品汇总
	public function get_pickcollect(){
		$m=M('Pickcollect',C('DB_PRS'),C('DB_DEPOT'));
		$Storage=M('Storage',C('DB_PRS'),C('DB_DEPOT'));
		$ck=A('CheckInput');
		//排序
        $sort=$ck->in('排序','sort','cnennumstr','id',0,0);
        $order=$ck->in('规则','order','cnennumstr','desc',0,0);
		
		//获取数据
        $info=$m->order($sort.' '.$order)->select();
		foreach($info as $k=>$v){
			$storage_info=$Storage->where(array('storage_code'=>$v['storage_code']))->find();
			$info[$k]['storage_code']=$storage_info['name'];
		}
		// $data['total']=$count;
        // $data['rows']=$info;
        $this->ajaxReturn($info);
	}
	//历史波次单
	public function historypicklist(){
		$this->display();
	}
	//获得历史波次单列表
	public function get_historypicklist(){
		$ck=A('CheckInput');
		//参数验证
        $picklist_no=$ck->in('波次单编号','picklist_no','ennumstr','',0,0);
        $page=$ck->in('当前页','page','intval','1',0,0);
        $rows=$ck->in('每页记录数','rows','intval','',0,0);
		$status=I('status');
		//排序
        $sort=$ck->in('排序','sort','cnennumstr','id',0,0);
        $order=$ck->in('规则','order','cnennumstr','desc',0,0);
		//搜索条件
		$map=array();
		
		!empty($picklist_no)?$map['picklist_no']=array('like','%'.$picklist_no.'%'):'';
		
		//获取数据
        // $data=getTable('Picklist',$map,$page,$rows,$sort,$order,$status);
		$m=M('Picklist',C('DB_PRS'),C('DB_DEPOT'));
		if($status==NULL){
			$map['status']=array('neq',-1);//未删除
		}else{
			$map['status']=$status;
		}

		$count=$m->where($map)->count();
		$info=$m->where($map)->page($page,$rows)->order($sort.' '.$order)->select();
		// echo $m->getlastsql();
		foreach($info as $k=>$v){
			if(!empty($v['update_time'])){
				$info[$k]['update_time']=date("Y-m-d H:i:s",$v['update_time']);
			}
			if(!empty($v['examine_time'])){
				$info[$k]['examine_time']=date("Y-m-d H:i:s",$v['examine_time']);
			}
			if(!empty($v['add_time'])){
				$info[$k]['add_time']=date("Y-m-d H:i:s",$v['add_time']);
			}
			if(!empty($v['overdue_time'])){
				$info[$k]['overdue_time']=date("Y-m-d H:i:s",$v['overdue_time']);
			}
			if($v['status']==-1){
				$info[$k]['status']="已删除";
			}
			if($v['status']==0){
				$info[$k]['status']="未审核";
				$info[$k]['color']=0;//设定颜色
			}
			if($v['status']==1){
				$info[$k]['status']="审核通过";
			}
			if($v['status']==2){
				$info[$k]['status']="审核未通过";
			}
		}
        if(!empty($info)){
            $data['total']=$count;
            $data['rows']=$info;
        }else{
            $data['total']=0;
            $data['rows']=0;
        }
        $this->ajaxReturn($data);
	}
	public function get_picklist(){
		$m=M('Pickorder',C('DB_PRS'),C('DB_DEPOT'));
		$param=I('param.','','trim');
		$map['order_id']=$param['order_id'];
		$m_info=$m->where($map)->find();
		alert_json(1,$m_info['picklist_no']);
	}
	//扫面单出库
	public function scanorder_emergency(){
		$mailno_status=C('base_config.mailno_status');
		
		if($mailno_status==1){
			C('scanorder.lang_name','面单');
		}else{
			C('scanorder.lang_name','订单');
		}
		$this->assign('is_emergency',1);
		$this->display('scanorder');
	}
	public function scanorder(){
		$mailno_status=C('base_config.mailno_status');
		
		if($mailno_status==1){
			C('scanorder.lang_name','面单');
		}else{
			C('scanorder.lang_name','订单');
		}
		$this->display();
	}
	//波次单查看
	public function picklistView(){
		$id=I('id');
		$m=M('Picklist',C('DB_PRS'),C('DB_DEPOT'));
		$Storage=M('Storage',C('DB_PRS'),C('DB_DEPOT'));//库位表
		$n=M('Pickorder',C('DB_PRS'),C('DB_DEPOT'));
		$p=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$gg=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
		$pr=M('Printorder',C('DB_PRS'),C('DB_DEPOT'));
		$Pickgoods=M('Pickgoods',C('DB_PRS'),C('DB_DEPOT'));
		$country=M('Country',C('DB_PRS'),C('DB_DEPOT'));
		$picklist_no=$m->where(array('id'=>$id))->getField('picklist_no');
        $picklist_time=$m->where(array('id'=>$id))->getField('add_time');

		// $Pickorder_list=$n->where('picklist_no="'.$picklist_no.'"')->select();
		$Pickorder_list=$n->alias('n')
						->join("__PUSHORDER__ p on n.order_id=p.id")
						->where(array('picklist_no'=>$picklist_no))
						->select();
		$Pickgoods_list=$Pickgoods->alias('p')->join('__STORAGE__ s on p.storage_code=s.storage_code','left')->where('p.picklist_no="'.$picklist_no.'"')->order('s.sort asc')->select();

		$order_no_arr=array();
		foreach($Pickorder_list as $key => $v){
			// $list=$p->field('order_no,logistics_no')->where('id='.$v['order_id'])->find();
			
			$order_no_arr[]=$v['order_no'];//订单列表
			// $list_print=$pr->where('order_no="'.$v['order_no'].'"')->find();//获取物流单号
			$Pickorder_list[$key]['order_no']=$v['order_no'];
			$Pickorder_list[$key]['mailNo']=$v['logistics_no'];
			/********显示订单商品明细************/
			$Pickorder_list[$key]['goods']=$gg->where('order_id='.$v['order_id'])->select();
			foreach($Pickorder_list[$key]['goods'] as $k=>$value){
				$Pickorder_list[$key]['goods'][$k]['country_name']=$country->where(array('country_code'=>$value['source']))->find();
                $Pickorder_list[$key]['nums_count_all'] += intval($value['goods_nums']);
				//$Pickorder_list[$key]['goods'][$k]['country_name']=$country->where(array('country_code'=>$value['source']))->find();
			}
		}
        $day = date("N",$picklist_time);
        if($day==1){$day ='一';}elseif($day==2){$day ='二';}elseif($day==3){$day ='三';}elseif($day==4){$day ='四';}elseif($day==5){$day ='五';}elseif($day==6){$day ='六';}elseif($day==7){$day ='日';}

		$count_list=$p->field('erp_mark_mailno,count(*) count')->where(array('order_no'=>array('in',$order_no_arr)))->group('erp_mark_mailno')->select();
		
		$this->assign('count_list',$count_list);
		$this->assign('day',$day);
    	$this->assign('picklist_no',$picklist_no);
    	$this->assign('picklist_time',$picklist_time);
		$this->assign('pickorder_list',$Pickorder_list);
		$this->assign('Pickgoods_list',$Pickgoods_list);
		$this->display();
	}
	//获得订单商品
	public function get_pickordergoods(){
		$g=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
		$order_id=I('order_id');
		$pickordergoods_list=$g->where(array('order_id'=>$order_id))->select();
		// dump($pickordergoods_list);
		$this->ajaxReturn($pickordergoods_list);
	}
	//获得波次单商品
	public function get_pickgoods(){
		$g=M('Pickgoods',C('DB_PRS'),C('DB_DEPOT'));
		$picklist_no=I('picklist_no');
		$pickgoods_list=$g->where(array('picklist_no'=>$picklist_no))->select();
		$this->ajaxReturn($pickgoods_list);
	}
	//生成拣货单
	public function makepicklist(){
		$trans = M('',C('DB_PRS'),C('DB_DEPOT'));
		$trans->startTrans();   // 开启事务
		$ao=M('ArrivalOrder',C('DB_PRS'),C('DB_DEPOT'));//商品详情入库单
		
		$orderlist=I('orderlist');
		$arr=explode('/',$orderlist);
		// $this->haspicklist($arr);//判断是否已生成波次单
		$m=M('Picklist',C('DB_PRS'),C('DB_DEPOT'));
		$n=M('Pickgoods',C('DB_PRS'),C('DB_DEPOT'));
		$p=M('Pickorder',C('DB_PRS'),C('DB_DEPOT'));
		$g=M('Pickcollect',C('DB_PRS'),C('DB_DEPOT'));
		$po=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$pog=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
		$t_no=serialNumber('Picklist');//流水号
		$picklist_no='P'.date('Ymd',time()).$t_no;//拣货单号
		$dataa['status']=1;
	    $dataa['add_time']=time();
	    $dataa['picklist_no']=$picklist_no;
		$status=$m->add($dataa);//添加拣货单数据
		
		if($status){
			$list=$g->select();
			foreach($list as $k=>$v){
				$data=array();
				$data['goods_name']=$v['goods_name'];
				$data['goods_no']=$v['goods_no'];
				$data['goods_count']=$v['goods_count'];
				$map_ao=array();
				$map_ao['goods_no']=$v['goods_no'];
				$map_ao['grounding_status']=1;
				$rule_freez=C('base_config.rule_freez');
                if($rule_freez){
                    $orderby="overdue_time";
                }else{
                    $orderby="add_time";
                }
				$ao_info=$ao->field('storage_code')->where($map_ao)->order($orderby.' desc')->limit(1)->find();//按商品入库批次顺序冻结库存
				$data['storage_code']=$ao_info['storage_code'];
				$data['storage_level']=$v['storage_level'];
				$data['add_time']=time();
				$data['picklist_no']=$picklist_no;
				if(empty($v['goods_no'])){
				   $trans->rollback();
				   $return['message']=$v['goods_no']."存在商品编码为空的商品";
				   $return['status']=false;
				   $this->ajaxReturn($return);
				}
				if(empty($v['goods_name'])){
				   $trans->rollback();
				   $return['message']=$v['goods_no']."存在商品名称为空的商品";
				   $return['status']=false;
				   $this->ajaxReturn($return);
				}
				if(empty($v['goods_count'])){
				   $trans->rollback();
				   $return['message']=$v['goods_no']."存在商品数量为空的商品";
				   $return['status']=false;
				   $this->ajaxReturn($return);
				}
				if(empty($ao_info['storage_code'])){
				   $trans->rollback();
				   $return['message']=$v['goods_no']."存在库位为空的商品";
				   $return['status']=false;
				   $this->ajaxReturn($return);
				}
				if($n->add($data)){
					continue;
				}else{
				   $trans->rollback();
				   $return['message']="生成对应商品数据失败";
				   $return['status']=false;
				   $this->ajaxReturn($return);
				}
			}
			
			$data_order['picklist_no']=$picklist_no;
			$data_order['add_time']=time();
			foreach($arr as $key=>$value){
				$orderid=$po->field('id')->where('order_no="'.trim($value).'"')->find();
				$pog_list=$pog->where(array('order_id'=>$orderid['id']))->select();//获得商品详情
				// dump($pog_list);
				// die;
				//自动关联批次-begin
				foreach($pog_list as $ks=>$vs){
					if(empty($vs['goods_batch_no'])){//如果没有关联过批次库存，则开始关联
						$freez_status=freez_storage($vs);//调用递归函数,自动关联批次库存(冻结库存)
						if($freez_status['status']){
							continue;
						}else{
							$this->ajaxReturn($freez_status);
						}
					}
				}
				//自动关联批次-end
				$data_po['pick_status']=1;//更新订单拣货状态
				$data_po['box_no']=$key+1;//关联拣货筐号
				$po->where('order_no="'.trim($value).'"')->save($data_po);
				$data_order['order_id']=$orderid['id'];
				$res=$p->add($data_order);
				
				if($res){
					continue;
				}else{
					$trans->rollback();
					$return['message']="生成对应订单数据失败";
				    $return['status']=false;
				    $this->ajaxReturn($return);
				}
			}
		}else{
			$trans->rollback();
			$return['message']="生成波次单失败";
			$return['status']=false;
			$this->ajaxReturn($return);
		}
		$trans->commit();
		$return['message']="生成波次单成功";
		$return['picklist_id']=$status;
		$return['status']=true;
		$this->ajaxReturn($return);
	}
	
	//确认上架
    public function confirm_grounding(){
		$m=M('Goods',C('DB_PRS'),C('DB_DEPOT'));
        if(!IS_POST) exit; 
        $ck=A('CheckInput');
        $data['bar_code']=$ck->in('条形码','bar_code','ennumstr','',2,30);
		$data['storage_code']=$ck->in('库位','storage_code','ennumstr','',1,10);
		$data['grounding_status']=1;
        $map['id']=$ck->in('erp企业id','id','intval','',1,0);
		
        $result=$m->where($map)->save($data);

        if(false===$result){
            $return['message']='上架失败';
            $return['status']=false;
            $this->ajaxReturn($return);
        }else{
			$return['message']='上架成功!';
			$return['status']=true; 
			$this->ajaxReturn($return);
        }
    }
	//批量下架
    public function ungrounding(){
		$m=M('Goods',C('DB_PRS'),C('DB_DEPOT'));
        if(!IS_POST) exit; 
        $ck=A('CheckInput'); 
        $id=$ck->in('库存商品id','id','string','',1,0);
        if(empty($id)) exit;//为空
        $arr=explode(',', $id);
        $map['id']=array('in',$arr);
		$data['storage_code']=0;
		$data['grounding_status']=0;
        $result=$m->where($map)->save($data);
        if($result===false){
            $return['message']='下架失败!';
            $return['status']=false;  
        }else{
            $return['message']='下架成功!';
            $return['status']=true; 
        }
        $this->ajaxReturn($return);
    }
	//是否已经生成过波次单
	public function haspicklist($list){
		foreach($list as $k=>$v){
		   $res=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'))->where('order_no="'.$v.'"')->find();
		   if($res){
			   $status=M('Pickorder',C('DB_PRS'),C('DB_DEPOT'))->where('order_id='.$res['id'])->find();
			   if($status){
				   $return['message']='订单:'.$v.'已经生成过波次单！请重新选择订单！';
				   $return['status']=false;
				   $this->ajaxReturn($return);
			   }
			}
		}
	}
	//批量打印顺丰面单--预览/直接打印
	public function ajax_printbatSF(){
	  $id=I('id');
	  $preview=I('preview');//预览参数
	  // $m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
	  $n=M('Printorder',C('DB_PRS'),C('DB_DEPOT'));
	  $g=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
	  $p=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
	  $printerid_list=explode(',',$id);
	  $map['id']=array('in',$printerid_list);
	  $order_list=$p->field('order_no')->where($map)->select();//订单列表
	  foreach($order_list as $keys=>$values){
		  $order_no_list[$keys]=$values['order_no'];
	  }
	  
	  $mapss['order_no']=array('in',$order_no_list);
	  $printorder_list=$n->where($mapss)->group('order_no')->order('id desc')->select();
	  // echo $n->getlastsql();
	  // if(empty($preview)){//非预览状态
		  $p->where($map)->save(array('printer_name'=>session('username'),'times'=>array('exp','times+1')));//更新打印次数
	  // }
		
	  foreach($printorder_list as $k=>$v){
		  $order_info=$p->field('id,box_no')->where(array('order_no'=>$v['order_no']))->find();
		  $order_id=$order_info['id'];
		  $goods_info=$g->where(array('order_id'=>$order_id))->select();
		  $count_ss=$g->field('sum(goods_nums) count_goods')->where(array('order_id'=>$order_id))->select();
		  $count=$count_ss[0]['count_goods'];
		  // $printorder_list[$k]['goods_info']=$goods_info;
		  // $count=count($goods_info);
		  $goods_text_head	='<p style="font-size:10px;line-height:12px;">';
		  $goods_text_body="";
		  foreach($goods_info as $ks=>$vs){
			 $goods_text_body.=$vs['goods_name'].'|'.$vs['goods_nums'];
		  }

		  $goods_text_body2=msubstr($goods_text_body,0,71,'utf-8',false);
		  $goods_text=$goods_text_head.$goods_text_body2.'</p>';
		  $text_head='<!DOCTYPE html>
						<html lang="zh-CN">
						<head>
							<meta charset="UTF-8">
							<meta http-equiv="X-UA-Compatible" content="IE=edge">
							<title>顺丰打印单</title>
							<link rel="icon" href="">
							<link rel="stylesheet" href="./Public/sf/css/common.css">
							<link rel="stylesheet" href="./Public/sf/css/style.css">
							<script type="text/javascript" src="./Public/Admin/lib/jquery/1.9.1/jquery.min.js"></script>
						<style rel="stylesheet" type="text/css" media="all" />
							@media print {
							.noprint { display: none; }
							.break {page-break-after:always;}
							}
						</style>
						</head>
						<body>';
			//$text_end='<div class="break" style="page-break-before:always;width:100%;height:0px;clear:both;">&nbsp;</div></body>';
			$text_body='<div class="page">
		<input type="hidden" class="order_no" value="'.$v['order_no'].'" name="order_no" />
		<div class="m1 b">
		商品数量:'.$count.'
		</div>
		<div class="m2 b">
			<div class="left">
			<img width="235.3px" height="60px" src="./Public/plugins/barcodegen/test_1D.php?text='.$v['mailNo'].'" alt="barcode"/>
				<p>单号<span>'.$v['mailNo'].'</span></p>
			</div>
			<div class="right">
				<div class="r1 b" >
					<p style="font-size:14px">顺丰特惠</p>
				</div>
				<div class="r2">
					<p class="p1"></p>
					<p class="p2">月结卡号：'.$v["custid"].'</p>
                    <p class="p2">付款方式:'.$v["pay_methods"].'</p>
				</div>
			</div>
		</div>
		<div class="m3 b">
			<div class="left">
				<p>目的地</p>
			</div>
			<div class="right">
				<p align="center">'.$v["destcode"].'</p>
			</div>
		</div>
		<div class="m4 b">
			<div class="left">
				<p>收件人</p>
			</div>
			<div class="right" >
				<p>
                 '.$v["receiveMan"].'
                 </p>
				<p>电话:'.$v["receiveManPhone"].'</p>
				<p>'.$v["receiveProvince"].$v["receiveCity"].$v["receiveCounty"].$v["receiveManAddress"].'</p>
			</div>
		</div>
		<div class="m5 b">
			<div class="left">
				<p>寄件人</p>
			</div>
			<div class="right-1" style="font-size:15px">
				<p>'.$v["sendMan"].'</p>
				<p>电话:'.$v["sendManPhone"].'</p>
				<p>'.$v["sendProvince"].$v["sendCity"].$v["sendCounty"].$v["sendManAddress"].'</p>
			</div>
			<div class="right-2">
				<p class="p1" style="font-size:13px">定时派送</p>
				<p class="p2">自寄 </p>
			</div>
		</div>
		<div class="m6 b cl">
			<div class="left">

				<div class="l2">
					<div class="l2-a">
						<p>托寄物</p>
					</div>
					<div class="l2-b">
					'.$goods_text.'
                     </div>
					<div class="l2-c">
						<ul>
							<li>收件员：</li>
							<li>收件日期：</li>
							<li>派件员：</li>
						</ul>
					</div>
				</div>
			</div>
			<div class="right">
				<p>签名：</p>
				<p class="p2">月<span>日</span></p>
			</div>
		</div>
		<div class="item b">
			<div class="m7 b cl">
				<div class="left">
					<img class="img1" src="./Public/sf/img/logo.jpg">
					<img src="./Public/sf/img/tel.png">
				</div>
				<div class="right">
				<img style="margin-top:10px" width="162.9px" height="48.2px;" src="./Public/plugins/barcodegen/test_1D.php?text='.$v['mailNo'].'" alt="barcode"/>
				</div>
			</div>
			<div class="m5 b">
				<div class="left">
					<p>寄件人</p>
				</div>
				<div class="right" >
					<p>'.$v["sendMan"].'    '.$v["sendManPhone"].'</p>
					<p>'.$v["sendProvince"].$v["sendCity"].$v["sendCounty"].$v["sendManAddress"].'</p>
				</div>
			</div>
			<div class="m5 b">
				<div class="left">
					<p>收件人</p>
				</div>
				<div class="right" style="width:95%">
                    <p>'.$v["receiveMan"].'&nbsp'.$v["receiveManPhone"].'</p>
                    <p>'.$v["receiveProvince"].$v["receiveCity"].$v["receiveCounty"].$v["receiveManAddress"].'</p>
				</div>
			</div>
            <div class="m10" style="height:50px;font-size: 20px;vertical-align: center">
                <p class="s2"  align="center" style="line-height: 40px">'.'打印时间：'.date('Y-m-d H:i:s',time())/*农宇-G20食材专供工厂*/.'('.$order_info['box_no'].')</p>
            </div>
		</div>
	</div>';
		$text[$k]=$text_head.$text_body.'</body></html>';
	  }
	 
	  $return['status']=1;
	  $return['info']=$text;
	  $this->ajaxReturn($return);
	}
	//批量打印百世面单--预览/直接打印
	public function ajax_printbatBS(){

	  $id=I('id');
	  $preview=I('preview');
	  $cod=I('cod');
	  
	  // $m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
	  $n=M('Printorder',C('DB_PRS'),C('DB_DEPOT'));
	  $g=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
	  $p=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
	  $printerid_list=explode(',',$id);
	  $map['id']=array('in',$printerid_list);
	  $order_list=$p->field('order_no')->where($map)->select();//订单列表

	  foreach($order_list as $keys=>$values){
		  $order_no_list[$keys]=$values['order_no'];
	  }
	  
	  $mapss['order_no']=array('in',$order_no_list);
	  $printorder_list=$n->where($mapss)->group('order_no')->order('id desc')->select();

	  // echo $n->getlastsql();
	  // if(empty($preview)){//非预览状态
		  $p->where($map)->save(array('printer_name'=>session('username'),'times'=>array('exp','times+1')));//更新打印次数
	  // }

	  
	  foreach($printorder_list as $k=>$v){
		  $order_info=$p->field('id,box_no,cod_money')->where(array('order_no'=>$v['order_no']))->find();
		  
		  if($cod==1){
			  $headstr='<td width="170px" style="border-bottom: 1px solid #000;background-color:#000">
				<div>
					<span style="font-family: \'黑体\';font-size: 18pt;color: #fff;">代收货款  '.sprintf("%.2f",$order_info['cod_money']).'元</span>
					<br>
				</div>
			</td>';
			
				$bodystr='<div style="width:68px;height: 50px;background-color:#000;color:#fff;">
									代收货款  '.sprintf("%.2f",$order_info['cod_money']).' 元
								</div>';
		  }else{
			  $headstr='<td width="170px" style="border-bottom: 1px solid #000;">
				<div>
					<span style="font-family: \'黑体\';font-size: 12pt;">标准快递</span><br>
					<span style="font-family: \'黑体\';font-size: 12pt;">成就商业•精彩生活</span><br>
					</div>
			</td>';
			
				$bodystr='<div style="width:68px;height: 50px;">
									
								</div>';
		  }
		  
		  $order_id=$order_info['id'];
		  $goods_info=$g->where(array('order_id'=>$order_id))->limit(20)->select();
		  $count_ss=$g->field('sum(goods_nums) count_goods')->where(array('order_id'=>$order_id))->select();
		  $count=$count_ss[0]['count_goods'];
		  // $printorder_list[$k]['goods_info']=$goods_info;
		  // $count=count($goods_info);
		  $goods_text="";
		  foreach($goods_info as $ks=>$vs){
				if(count($goods_info)>1){
					$goods_name=mb_substr($vs['goods_name'],0,9,'utf-8');
				}else{
					$goods_name=$vs['goods_name'];
				}
				$goods_text.='<span style="font-family: \'宋体\';font-size:9pt;">'.$vs['goods_nums'].'*'.substr($vs['goods_no'],10).' '.$goods_name.'</span><br>';
			 // $goods_text='<p style="font-size: 12px;">'.msubstr($vs['goods_name'],0,12).'</p>
                        // <p style="font-size: 12px;">数量:'.$vs['goods_nums'].'</p>';
		  }
		  $text_head='<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>百世面单</title>
<style rel="stylesheet" type="text/css" media="all" >
body {
margin:0 9px 9px 9px;
width:450px;
padding: 0;
color: black;
text-decoration: none;
font-size: 11pt;
font-weight:bold;
font-family: "Courier New";
}
.ems input {
	font-family: Arial;
}

.ems th {
	font-weight: normal;
	border-bottom: 1px solid black;
}

.ems td {
	font-size: 9pt;
	font-family: "Courier New";
}

.ems td.pod {
	font-size: 11pt;
	font-family: "Courier New";
}

.ems td.t1{
	font-size:1pt;
	font-family:"宋体";
}
.ems th.pod {
	font-size: 11pt;
	font-family: "Courier New";
}

.ems td.endline {
	border-top: 1px solid black;
}

.ems .left {
	text-align: left;
}

.ems .right {
	text-align: right;
}

.ems .center {
	text-align: center;
}

.ems .top {
	vertical-align: top;
}

@media print {
	.break {page-break-after:always;}
}

</style>
<script type="text/javascript" src="./Public/Admin/lib/jquery/1.9.1/jquery.min.js"></script>
</head>

<body>';
			$text_end='<div class="break" style="page-break-before:always;width:100%;height:0px;clear:both;">&nbsp;</div></body>';
			$text_body='<table id="emstable" cellspacing="0" style="margin-left:0;margin-top:1px;float:left;width:380px;font-size:11pt;float: left;">
	<tr style="width: 330px;" height="40.2px">
		<td width="192px" style="border-bottom: 1px solid #000;vertical-align:top;">
		</td>
				'.$headstr.'
	</tr>
	<tr>
		<td colspan="2">
			<table   width="368px";cellspacing="0" cellpadding="0" style="margin-left: 10px;border-bottom: 1px solid #000;">
				<tr>
					<td width="100px" height="40px" >
						<div style="width:100px;height: 40px;">
							<b><span style="font-family: \'黑体\';font-size: 26pt;">'.$v["destcode"].'</span></b>
						</div>
					</td>
					<td width="240px">
						<div style="width: 240px; height:40px;">
							<b><span style="font-family: \'黑体\';font-size: 26pt;">'.$v["sortingCode"].'</span></b><br>
						</div>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	
	<tr>
		<td colspan="2">
			<table   width="368px";cellspacing="0" cellpadding="0" style="margin-left: 10px;border-bottom: 1px solid #000;">
				<tr>
					<td width="330px" height="40px">
						<div style="width:330px;">
							<b style="float:left;"><span style="font-family: \'黑体\';font-size: 20pt;">'.$v["pkgCode"].'</span></b>
							<span style="margin-top:4px;float:right;font-size:10px;">
								订单号：'.$v["order_no"].'<br>件数:'.$count.'
							</span>
						</div>
					
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
			<td colspan="2">
			<table width="330px"; cellspacing="0" style="padding-left: 10px;">
				<tr>
					<td  width="14px"; height="65px" style="border-right: 1px solid #000;border-bottom: 1px solid #000;">
						<div style="width: 14px; height: 65px;">
							<span>收件</span>
						</div>
					</td>

					<td width="237.85px" height="65px" style="border-right: 1px solid #000;border-bottom: 1px solid #000; ">
						<div style="width: 237.85px; height: 65px; padding: 0px;line-height: 16px;">
							<span style="font-family: \'宋体\';font-size: 10pt;">'.$v["receiveMan"].'</span><br>
							<span style="font-family: \'宋体\';font-size: 10pt;">电话：'.$v["receiveManPhone"].'</span><br>
							<span style="font-family: \'宋体\';font-size: 10pt;">地址：'.$v["receiveProvince"].$v["receiveCity"].$v["receiveCounty"].$v["receiveManAddress"].'</span>

						</div>
					</td>
					
			
					<td rowspan="2" width="100px" style="border-bottom: 1px solid #000;">

							<div style="width: 105px; height: 130px; padding: 0; margin: 0;">
							
						</div>
					</td>
				</tr>
				<tr>
					<td  width="330px"; height="65px" style="border-right: 1px solid #000;border-bottom: 1px solid #000;">
						<div style="width: 14px; height: 65px;">
						<span>寄件</span></td>
						</div>
					<td width="237.85px" height="65px" style="border-right: 1px solid #000;border-bottom: 1px solid #000;line-height: 16px;">
						<div style="width: 237.85px; height: 65px;">
							<span style="font-family: \'宋体\';font-size: 10pt;">'.$v["sendMan"].'</span><br>
							<span style="font-family: \'宋体\';font-size: 10pt;">电话：'.$v["sendManPhone"].'</span><br>
							<span style="font-family: \'宋体\';font-size: 10pt;">地址：'.$v["sendProvince"].$v["sendCity"].$v["sendCounty"].$v["sendManAddress"].'</span>
						</div>
					</td>
				</tr>
			</table>
			</td>
	</tr>
	<tr>
		<td width="330px" style="border-bottom: 1px solid #000;" colspan="2">
			<table width="330px" style="margin-left: 10px;" >
				<tr>
					<td width="330px">
						<div style="width:235.3px;height: 65px; text-align: center; margin: 0 auto;">
							<img width="235.3px" height="65px" src="./Public/plugins/barcodegen/test_1D.php?text='.$v['mailNo'].'" alt="barcode"/>
							
						</div>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td width="330px" height="50px" colspan="2">

			<div style="height: 50px;">
				<table width="330px"; cellspacing="0" style="margin-left: 10px;">
					<tr>
							<td width="200px" height="50px" style="border-top: 1px solid #000;border-right: 1px solid #000;border-bottom: 1px solid #000;">

								<div style="width: 200px; height: 50px;font-size:12px;">
								您对此单的签收，代表您已验收，确认商品信息无误，包装完好、没有划痕、破损等表面质量问题。
							</div>
						</td>
						<td width="90px" height="50px" style="border-top: 1px solid #000;border-right: 1px solid #000;border-bottom: 1px solid #000;" cellpadding="0" cellspacing="0">
							<div style="width: 90px; height: 50px;">
								<span style="font-family: \'宋体\';font-size: 10pt;">收件人</span><br><br>
								<span style="font-family: \'宋体\';font-size: 10pt;">时间</span>
							</div>
						</td>
						<td  width="68px" height="50px" style="border-top: 1px solid #000;border-bottom: 1px solid #000;">
							'.$bodystr.'
						</td>
					</tr>
				</table>
				
			</div>
		</td>
	</tr>
	<tr>
		<td colspan="2">
		<table width="368px" height="60.3px" style="border-bottom: 1px solid #000; margin-left: 10px;padding-top:18px;">
			<tr>
				<td width="200px" height="60.3px"></td>
				<td width="162.9px" height="60.3px">
					<div style="width;162.9px; height: 48.2px;margin-right:10px;">
						<img width="162.9px" height="48.2px;" src="./Public/plugins/barcodegen/test_1D.php?text='.$v['mailNo'].'" alt="barcode"/>
					</div>
				</td>
			</tr>		
		</table>
		</td>
	</tr>
	<tr>
		<td colspan="2">
		<table width="330px"; height="120.7px" cellspacing="0" style="padding-left: 10px;">
			<tr>
				<td  width="14px"; height="60.3px" style="border-right: 1px solid #000;border-bottom: 1px solid #000;">
					<div style="width: 14px; height: 60.3px;">
						<span>收件</span>
					</div>
				</td>
				<td width="237.85px" height="65px" style="border-right: 1px solid #000;border-bottom: 1px solid #000;">
					<div style="width: 237.85px; height: 65px;line-height:15px;">
						<span style="font-family: \'宋体\';font-size: 10pt;">'.$v["receiveMan"].'</span><br>
						<span style="font-family: \'宋体\';font-size: 10pt;">电话：'.$v["receiveManPhone"].'</span><br>
						<span style="font-family: \'宋体\';font-size: 10pt;">地址：'.$v["receiveProvince"].$v["receiveCity"].$v["receiveCounty"].$v["receiveManAddress"].'</span>

					</div>
				</td>
			
				<td rowspan="2" width="100px" height="120.7px" style="border-bottom: 1px solid #000;">

						<div style="width: 100px; height: 120.7px; padding: 0; margin: 0;">
						</div>
				</td>
			</tr>
				
			<tr>
				<td  width="330px"; height="60.3px" style="border-right: 1px solid #000;border-bottom: 1px solid #000;">
					<div style="width: 14px; height: 60.3px;">
						<span>寄件</span>
					</div>
				</td>

				<td width="237.85px" height="60.3px" style="border-right: 1px solid #000;border-bottom: 1px solid #000;">
					<div style="width: 237.85px; height: 65px;line-height:15px;">
						<span style="font-family: \'宋体\';font-size: 10pt;">'.$v["sendMan"].'</span><br>
						<span style="font-family: \'宋体\';font-size: 10pt;">电话：'.$v["sendManPhone"].'</span><br>
						<span style="font-family: \'宋体\';font-size: 10pt;">地址：'.$v["sendProvince"].$v["sendCity"].$v["sendCounty"].$v["sendManAddress"].'</span>
					</div>
				</td>	
			</tr>
			<tr>
				<td  width="330px"; height="58px" style="border-right: 1px solid #000;border-bottom: 0;">
					<div style="width: 14px; height: 58px;">
						<span>内件</span>
					</div>
				</td>
				<td width="337.85px" height="58px" colspan="2" style="border-bottom: 0;">
					<div style="width: 70px; height: 58px;line-height:15px;float:left;border-right:1px solid #000;">
						<span style="font-family: \'宋体\';font-size: 10pt;">总件数:'.$count.'</span>
					</div>
					<div style="width: 269px; float:left;height: 58px;line-height:15px;">
						<div style="width: 42px; height: 58px;line-height:15px;float:left;">
							<span style="font-family: \'宋体\';font-size: 10pt;">品名：</span>
						</div>
						<div style="width: 227px; font-size:8px;height: 39px;line-height:13px;float:left;overflow:hidden;">
							'.$goods_text.'
						</div>
						<span style="float:right;font-size:8pt;">已检视(<span style="font-size:22px">'.$order_info['box_no'].'</span>)</span>
					</div>
				</td>
			</tr>	
		</table>
		</td>
	</tr>
</table>';
		$text[$k]=$text_head.$text_body.$text_end;
	  }
	 
	  $return['status']=1;
	  $return['info']=$text;
	  // echo $text;
	  $this->ajaxReturn($return);
	}
	//批量打印百世英文面单--预览/直接打印
	public function ajax_printbatBSE(){
	  $id=I('id');
	  // dump($id);
	  $preview=I('preview');
	  // $m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
	  $n=M('Printorder',C('DB_PRS'),C('DB_DEPOT'));
	  $g=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
	  $p=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
	  $printerid_list=explode(',',$id);
	  $map['id']=array('in',$printerid_list);
	  $order_list=$p->field('order_no')->where($map)->select();//订单列表
	  // echo $p->getlastsql();
	  foreach($order_list as $keys=>$values){
		  $order_no_list[$keys]=$values['order_no'];
	  }
	  
	  $mapss['order_no']=array('in',$order_no_list);
	  $printorder_list=$n->where($mapss)->group('order_no')->order('id desc')->select();
	  // echo $n->getlastsql();
	  // if(empty($preview)){//非预览状态
		  $p->where($map)->save(array('printer_name'=>session('username'),'times'=>array('exp','times+1')));//更新打印次数
	  // }
	  
	  // dump($printorder_list);
	  // die;
	  foreach($printorder_list as $k=>$v){
		  $order_info=$p->field('id,box_no')->where(array('order_no'=>$v['order_no']))->find();
		  $order_id=$order_info['id'];
		  $goods_info=$g->where(array('order_id'=>$order_id))->limit(20)->select();

		  $count_ss=$g->field('sum(goods_nums) count_goods')->where(array('order_id'=>$order_id))->select();
		  $count=$count_ss[0]['count_goods'];
		  // echo $g->getlastsql();
		  // die;
		  // $printorder_list[$k]['goods_info']=$goods_info;
		  // $count=count($goods_info);
		  foreach($goods_info as $ks=>$vs){
			 $goods_text='<p style="font-size: 12px;">'.msubstr($vs['goods_name'],0,22).'数量:'.$vs['goods_nums'].'</p>';
                        
		  }
		  $text_head='<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>百世面单</title>
<style type="text/css">
body,html{padding: 0; margin:0;color:#333;text-decoration: none;font-size: 9pt;font-family:Arial, Helvetica, sans-serif;}
p{margin:0; padding:0;}
.clear{clear:both;}
.ord_warp{width:365px; margin:0 auto; height:auto; height:auto; border:1px solid #333;}
.ord_top{height:45px; width:100%; padding:0px 10px;}
.ord_logo{padding-top:7px;float:left; width:50%;}
.ord_tr{float:left; width:50%;}
.ord_tf{font-size:14pt; font-weight:bold; padding-top:2px;}
.ord_te{font-family:Arial, Helvetica, sans-serif; font-size:9pt; color:#4A4A4A;}
.ord_title{border-top:1px solid #000; border-bottom:1px solid #333; padding:3px 0px;}
.ord_title p{font-size:17pt; font-weight:bold;text-align:center; font-family:"微软雅黑"}
.ord_te2{font-family:Arial, Helvetica, sans-serif; font-size:10pt; text-align:center; display:block; color:#4A4A4A;}
.ord_main{width:100%;}
.ord_ml{width:220px; float:left;}
.ord_mlm{width:100%; border-bottom:1px solid #333;}
.ord_mlt{width:49px; float:left; text-align:center; padding-top:35px;}
.ord_mlt2{width:50px; float:left; text-align:center;padding-top:22px;}
.ord_mlt_s{ font-weight:bold;font-family:"微软雅黑"}
.ord_te3{font-family:Arial, Helvetica, sans-serif; font-size:9pt;color:#4A4A4A; font-weight:bold; text-transform:capitalize;}
.ord_mlx{width:170px; padding:5px 0px; float:left; border-left:1px solid #333;font-weight:bold; height:85px;}
.ord_mlx p{padding:0px 5px; font-weight:bold; padding-bottom:4px; line-height:13px;}
.ord_mr{float:left; width:144px; border-left:1px solid #333; }
.order_s{width:100%; padding:5px 0px; text-align:center; border-bottom:1px solid #333;}
.order_sm{padding:5px; border-bottom:1px solid #333; height:138px;}
.ord_mlt_s2{ font-size:9pt; line-height:14px; padding-bottom:4px;font-family:"微软雅黑"}
.ord_te4{font-family:Arial, Helvetica, sans-serif; font-size:9pt;color:#4A4A4A;text-transform:capitalize;}
.ord_inp{border:0px; width: 25px;font-size: 9pt; font-weight:bold; outline:none; padding-left:2px; line-height:14px; width:67px;}
.ord_cod{width:100%; padding:8px 0px;}
.ord_cod img{ display:block; margin:0 auto;}
.ord_qian{width:100%; border-bottom:1px solid #333; border-top:1px solid #333; height:70px;}
.ord_ql{width:45%; float:left;}
.ord_ql p{font-family:Arial, Helvetica, sans-serif;font-size:9pt;color:#333; line-height:13px; padding:3px 5px 0px 5px;}
.ord_qm{width:53.7%; float:left; border-left:1px solid #333; height:70px;}
.ord_qm p{padding-left:5px; padding-top:7px;font-weight:bold;}

.ord_midd{padding:20px 10px 5px; border-bottom:1px solid #333;}
.ord_midd_l{padding-top:8px; float:left;}
.ord_midd_r{float:right;}
.ord_tb{width:100%;}
.ord_ml2{width:365px;}
.ord_mlx2{width:314px; padding:2px 0px; float:left; border-left:1px solid #333;font-weight:bold;height:64px;}
.ord_mlx2 p{padding:0px 5px; font-weight:bold; padding-bottom:4px; line-height:13px;}
.ord_footer{height:25px; width:100%;}
.ord_footer p{text-align:right; padding-right:5px; padding-top:8px;}
@media print {
	.break {page-break-after:always;}
}
</style>
<script type="text/javascript" src="./Public/Admin/lib/jquery/1.9.1/jquery.min.js"></script>
</head>

<body>';
			$text_end='<div class="break" style="page-break-before:always;width:100%;height:0px;clear:both;">&nbsp;</div></body>';
			$text_body='<div class="ord_warp">
  <div class="ord_top">
    <div class="ord_logo"></div>
    <div class="ord_tr">
      <p class="ord_tf">成就商业•精彩生活</p>
      <p class="ord_te">Make a good life in business</p>
    </div>
    <div class="clear"></div>
  </div>
  
  <div class="ord_title">
    <p>'.$v["destcode"].'</p><span class="ord_te2">'.$v["destcode"].'</span>
  </div>
  
  <div class="ord_main">
    <div class="ord_ml">
     <div class="ord_mlm">
      <div class="ord_mlt">
        <p class="ord_mlt_s">收件</p><p class="ord_te3">receive</p>
      </div>
      <div class="ord_mlx">
        <p>'.$v["receiveMan"].'</p>
        <p>Tel:'.$v["receiveManPhone"].'</p>
        <p>Add:'.$v["receiveProvince"].$v["receiveCity"].$v["receiveCounty"].$v["receiveManAddress"].'</p>
      </div>
      <div class="clear"></div>
     </div> 
     
     <div class="ord_mlm">
      <div class="ord_mlt">
        <p class="ord_mlt_s">寄件</p><p class="ord_te3">sent</p>
      </div>
      <div class="ord_mlx">
        <p>'.$v["sendMan"].'</p>
        <p>Tel:'.$v["sendManPhone"].'</p>
        <p>Add:'.$v["sendProvince"].$v["sendCity"].$v["sendCounty"].$v["sendManAddress"].'</p>
      </div>
      <div class="clear"></div>
     </div>
     
    </div>
    
    <div class="ord_mr">
      <div class="order_s">
        <p class="ord_mlt_s">服务</p>
        <p class="ord_te3">service</p>
      </div>
      <div class="order_sm">
        <p class="ord_mlt_s2">品名：'.$goods_text.'</p>
        
      </div>
      
    </div>
    
    <div class="clear"></div>
  </div>
  
  <div class="ord_cod"><img src="./Public/plugins/barcodegen/test_1D.php?text='.$v['mailNo'].'" width="189" height="55" /></div>
  <div class="ord_qian">
    <div class="ord_ql"><p>您对此单的签收，代表您已验收，确认商品信息无误，包装完好、没有划痕、破损等表面质量问题。</p></div>
    <div class="ord_qm">
      <p>收件人<br>receiver:<br>
      时间<br>time:
	  </p>
    </div>

    <div class="clear"></div>
  </div>
  
  <div class="ord_midd">
    
    <img src="./Public/plugins/barcodegen/test_1D.php?text='.$v['mailNo'].'" width="155" height="55" class="ord_midd_r"/>
    <div class="clear"></div>
   </div>
   
    <div class="ord_ml2">
     <div class="ord_mlm">
      <div class="ord_mlt2">
        <p class="ord_mlt_s">收件</p><p class="ord_te3">receive</p>
      </div>
      <div class="ord_mlx2">
        <p>'.$v["receiveMan"].'</p>
        <p>Tel:'.$v["receiveManPhone"].'</p>
        <p>Add:'.$v["receiveProvince"].$v["receiveCity"].$v["receiveCounty"].$v["receiveManAddress"].'</p>
      </div>
      <div class="clear"></div>
     </div> 
     
     <div class="ord_mlm">
      <div class="ord_mlt2">
        <p class="ord_mlt_s">寄件</p><p class="ord_te3">sent</p>
      </div>
      <div class="ord_mlx2">
        <p>'.$v["sendMan"].'</p>
        <p>Tel:'.$v["sendManPhone"].'</p>
        <p>Add:'.$v["sendProvince"].$v["sendCity"].$v["sendCounty"].$v["sendManAddress"].'</p>
      </div>
      <div class="clear"></div>
     </div>
     
    </div>
    
  <div class="ord_footer">
    <p class="ord_mlt_s">商品数量:'.$count.'  已检视(<span style="font-size:12px">'.$order_info['box_no'].'</span>)<span class="ord_te3">(View planned cost)</span></p>
  </div>

   
</div>';
			$text[$k]=$text_head.$text_body.$text_end;
	  }
	 
	  $return['status']=1;
	  $return['info']=$text;
	  $this->ajaxReturn($return);
	}
	
	//批量打印中通面单--预览/直接打印
	public function ajax_printbatZTO(){
	  $id=I('id');
	  $preview=I('preview');
	  // $m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
	  $n=M('Printorder',C('DB_PRS'),C('DB_DEPOT'));
	  $g=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
	  $p=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
	  $printerid_list=explode(',',$id);
	  $map['id']=array('in',$printerid_list);
	  $order_list=$p->field('order_no')->where($map)->select();//订单列表
	  foreach($order_list as $keys=>$values){
		  $order_no_list[$keys]=$values['order_no'];
	  }
	  
	  $mapss['order_no']=array('in',$order_no_list);
	  $printorder_list=$n->where($mapss)->group('order_no')->order('id desc')->select();
	  // echo $n->getlastsql();
	  // if(empty($preview)){//非预览状态
		  $p->where($map)->save(array('printer_name'=>session('username'),'times'=>array('exp','times+1')));//更新打印次数
	  // }
	  
	  // dump($printorder_list);
	  // die;
	  foreach($printorder_list as $k=>$v){
		  $order_info=$p->field('id,box_no')->where(array('order_no'=>$v['order_no']))->find();
		  $order_id=$order_info['id'];
		  $goods_info=$g->where(array('order_id'=>$order_id))->limit(20)->select();
		  $count_ss=$g->field('sum(goods_nums) count_goods')->where(array('order_id'=>$order_id))->select();
		  $count=$count_ss[0]['count_goods'];
		  // $printorder_list[$k]['goods_info']=$goods_info;
		  // $count=count($goods_info);
		  foreach($goods_info as $ks=>$vs){
			 $goods_text='<p style="font-size: 12px;">'.msubstr($vs['goods_name'],0,12).'</p>
                        <p style="font-size: 12px;">数量:'.$vs['goods_nums'].'</p>';
		  }
		  $text_head='<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>百世面单</title>
<style>
@media print {
	.break {page-break-after:always;}
}
body,html{padding: 0; margin:0;color:#333;text-decoration: none;font-size:8pt;font-family:"微软雅黑";-webkit-text-size-adjust:none;}
p{margin:0; padding:0;}
.clear{clear:both;}
.or_warp{width:378px;height:auto; margin:0 auto; border:2px solid #2a6082;}
.or_main{height:98%; width:96%; border:4px solid #0969b3; margin:1% auto;}
.or_top{height:40px; border-bottom:1px solid #000;}
.or_logo{width:110px; height:28px; float:left; padding:6px 0px 0px 10px;}
.or_tright{float:right; font-size:12pt; color:#fff; line-height:40px; padding:0px 10px; background-color:#000;}
.or_titlte{height:40px; text-align:center; line-height:40px; font-size:18pt; font-weight:bold; border-bottom:1px solid #000;}
.or_table{border-bottom:8px solid #000; height:auto;}
.or_fmain{border-bottom:1px solid #000; height:140px;}
.or_tatop{height:36px; line-height:36px;}
.or_tat_l{width:70%; float:left; text-align:center; font-size:13pt; font-weight:bold;}
.or_tat_r{width:29%; float:left; text-align:center; border-left:1px solid #000;}
.or_ml{width:70%; float:left;}
.or_ml_jian{width:100%; border-top:1px solid #000;height:70px;}
.or_ml_l{width:12px; float:left;padding:18px 10px 0px 10px;}
.or_ml_l2{width:15px; float:left;padding:25px 10px 0px 10px;} 
.or_ml_r{width:83%; float:left; border-left:1px solid #000;  padding:5px 5px 15px 5px;height:50px;}
.or_ml_rf{font-size:8pt; line-height:14px; margin-bottom:3px;}
.or_ml_rf2{font-size:8pt; font-weight:bold; line-height:14px; margin-top:1px;}
.or_mr{width:29.5%; float:left;border-left:1px solid #000;border-top:1px solid #000;height:140px;}
.or_mr_t{ border-bottom:1px solid #000; height:24px; line-height:24px; text-align:center;}
.or_mr_b{padding-left:2px;}
.or_mr_b p{line-height:14px;}
.or_tacode{
	padding:3px 0;
}
.or_tacode img{display:block; margin:2px auto;width:250px;height:62px;}
.or_tabo{border-top:1px solid #000; height:75px}
.or_taba_l{width:52%; float:left; font-size:8pt; line-height:14px; padding:2px 5px 0px 5px; height:75px;}
.or_taba_m{width:23%; float:left; border-left:1px solid #000; border-right:1px solid #000; height:75px;}
.or_taba_m p{font-size:9pt; font-weight:bold; line-height:16px; padding-left:5px; padding-top:15px;}
.or_taba_r{width:20%; float:left; font-weight:bold; text-align:center; line-height:20px; padding-top:5%;height:75px;}
.or_boto{padding:2px 10px; border-bottom:1px solid #000;}
.logo2{float:left; padding-top:10px;}
.code2{float:right;}
.or_ml2{width:100%;}
.or_bobo{height:30px; padding:1px 10px; border-top:1px solid #000;}
.or_bobo2{text-align:right; padding-top:0px;}
.shuiyin {  
    text-align:center; 
	width: 378px;
	font-size: 50px;
	top: 100px;
	position: absolute;
    color:rgb(200,200,200);  
}
</style>
<script type="text/javascript" src="./Public/Admin/lib/jquery/1.9.1/jquery.min.js"></script>
</head>

<body>';
			$text_end='<div class="break" style="page-break-before:always;width:100%;height:0px;clear:both;">&nbsp;</div></body>';
			$text_body='<div class="or_warp">
  <div class="or_main">
    <div class="or_top">
      <div class="or_logo"></div>
      <div class="or_tright">标准快递&nbsp;</div>
      <div class="clear"></div>
    </div>
    <div class="or_titlte">'.$v["destcode"].'</div>
    <div class="or_table">
      <div class="or_tatop">
        <div class="or_tat_l">'.$v["billProvideSiteName"].'</div>
        <div class="or_tat_r">'.date("Y-m-d",$v["add_time"]).'</div>
        <div class="clear"></div>
      </div>
      <div class="or_fmain">
        <div class="or_ml">
          <div class="or_ml_jian">
            <div class="or_ml_l">收件</div>
            <div class="or_ml_r">
              <p class="or_ml_rf">'.$v["receiveMan"].'&nbsp;&nbsp;'.$v["receiveManPhone"].'</p>
              <p class="or_ml_rf2">'.$v["receiveProvince"].$v["receiveCity"].$v["receiveCounty"].$v["receiveManAddress"].'</p>
            </div>
            <div class="clear"></div>
          </div>
          
          <div class="or_ml_jian">
            <div class="or_ml_l">寄件</div>
            <div class="or_ml_r" style="height:49px;">
              <p class="or_ml_rf">'.$v["sendMan"].'&nbsp;&nbsp;'.$v["sendManPhone"].'</p>
              <p class="or_ml_rf">'.$v["sendProvince"].$v["sendCity"].$v["sendCounty"].$v["sendManAddress"].'</p>
            </div>
            <div class="clear"></div>
          </div>
          
        </div>
        <div class="or_mr">

        </div>
        <div class="clear"></div>
      </div>
      <div class="or_tacode"><img src="./Public/plugins/barcodegen/test_1D.php?text='.$v['mailNo'].'" alt="barcode"/></div>
      <div class="or_tabo">
        <div class="or_taba_l">
          快件送达收件人地址，经收件人或收件人（寄件人）允许的代收人签字，视为送达。您的签字代表您已验收此包裹，并已确认商品信息无误，包装完好，没有划痕、破损等表面质量问题。
        </div>
        <div class="or_taba_m">
          <p>签收人：</p>
          <p>时间：</p>
        </div>
        <div class="or_taba_r"></div>
        <div class="clear"></div>
      </div>
    <div>

    
  </div>
</div>

    <div class="or_boto">
	  <span style="width:130px;height:28px;float:left;">&nbsp;</span>
      <img width="195" height="50" src="./Public/plugins/barcodegen/test_1D.php?text='.$v['mailNo'].'" alt="barcode"/>
      <div class="clear"></div>
    </div>
    
       <div class="or_ml2">
          <div class="or_ml_jian">
            <div class="or_ml_l2">收件</div>
            <div class="or_ml_r">
              <p class="or_ml_rf">'.$v["receiveMan"].'&nbsp;&nbsp;'.$v["receiveManPhone"].'</p>
              <p class="or_ml_rf">'.$v["receiveProvince"].$v["receiveCity"].$v["receiveCounty"].$v["receiveManAddress"].'</p>
            </div>
            <div class="clear"></div>
          </div>
          
          <div class="or_ml_jian">
            <div class="or_ml_l2">寄件</div>
            <div class="or_ml_r">
              <p class="or_ml_rf">'.$v["sendMan"].'&nbsp;&nbsp;'.$v["sendManPhone"].'</p>
              <p class="or_ml_rf">'.$v["sendProvince"].$v["sendCity"].$v["sendCounty"].$v["sendManAddress"].'</p>
            </div>
            <div class="clear"></div>
          </div>

        </div>
        
        <div class="or_bobo">
          <p>商品数量:<span style="font-size:22px">'.$count.'</span><span style="float:right">已检视(<span style="font-size:22px">'.$order_info['box_no'].'</span>)</span></p>
        </div></div></div>';
		$text[$k]=$text_head.$text_body.$text_end;
		// $text[$k]['watermark']=$v['destcode'];
	  }
	 
	  $return['status']=1;
	  $return['info']=$text;
	  $this->ajaxReturn($return);
	}
	//批量打印圆通面单--预览/直接打印
	public function ajax_printbatYT(){
		  $id=I('id');
		  $preview=I('preview');
		  $n=M('Printorder',C('DB_PRS'),C('DB_DEPOT'));
		  $g=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
		  $p=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		  $pk=M('Packing',C('DB_PRS'),C('DB_DEPOT'));
		  
		  $printerid_list=explode(',',$id);
		  $map=array();
		  $map['id']=array('in',$printerid_list);
		  $order_list=$p->field('order_no')->where($map)->select();//订单列表
		  foreach($order_list as $keys=>$values){
			  $order_no_list[$keys]=$values['order_no'];
		  }
		  $mapss=array();
		  $mapss['order_no']=array('in',$order_no_list);
		  $printorder_list=$n->where($mapss)->group('order_no')->order('id desc')->select();

		  // if(empty($preview)){//非预览状态
			  $p->where($map)->save(array('printer_name'=>session('username'),'times'=>array('exp','times+1')));//更新打印次数
		  // }
		  foreach($printorder_list as $k=>$v){
			  $v['total_weight']=$pk->where(array('order_no'=>$v['order_no']))->getField('pack_weight');
			  $order_info=$p->field('id,box_no')->where(array('order_no'=>$v['order_no']))->find();
			  $order_id=$order_info['id'];
			  $box_no=$order_info['box_no'];
			  // $goods_info=$g->where(array('order_id'=>$order_id))->limit(20)->select();
			  $count_ss=$g->field('sum(goods_nums) count_goods')->where(array('order_id'=>$order_id))->select();
			  $v['count']=$count_ss[0]['count_goods'];

			  $this->assign('v',$v);
			  $this->assign('box_no',$box_no);
			  // dump($v);
			  $text_print=$this->fetch('Outbound/logistics/logistics_yt');

			  $text[$k]=$text_print;
		  }
		   
		  $return['status']=1;
		  $return['info']=$text;
		  $this->ajaxReturn($return);
	}
	
	//批量打印申通面单--预览/直接打印
	public function ajax_printbatST(){
		  $id=I('id');
		  $preview=I('preview');
		  $n=M('Printorder',C('DB_PRS'),C('DB_DEPOT'));
		  $g=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
		  $p=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		  $pk=M('Packing',C('DB_PRS'),C('DB_DEPOT'));
		  
		  $printerid_list=explode(',',$id);
		  $map=array();
		  $map['id']=array('in',$printerid_list);
		  $order_list=$p->field('order_no')->where($map)->select();//订单列表
		  foreach($order_list as $keys=>$values){
			  $order_no_list[$keys]=$values['order_no'];
		  }
		  $mapss=array();
		  $mapss['order_no']=array('in',$order_no_list);
		  $printorder_list=$n->where($mapss)->group('order_no')->order('id desc')->select();

		  // if(empty($preview)){//非预览状态
			  $p->where($map)->save(array('printer_name'=>session('username'),'times'=>array('exp','times+1')));//更新打印次数
		  // }
		  foreach($printorder_list as $k=>$v){
			  $v['total_weight']=$pk->where(array('order_no'=>$v['order_no']))->getField('pack_weight');
			  $order_info=$p->field('id,box_no')->where(array('order_no'=>$v['order_no']))->find();
			  $order_id=$order_info['id'];
			  $box_no=$order_info['box_no'];
			  $goods_info=$g->where(array('order_id'=>$order_id))->limit(20)->select();
			  
			  $goods_text_body="";
			  foreach($goods_info as $ks=>$vs){
				 $goods_text_body.=$vs['goods_name'].'|'.$vs['goods_nums'];
			  }
			  $goods_text=msubstr($goods_text_body,0,71,'utf-8',false);
			  
			  $count_ss=$g->field('sum(goods_nums) count_goods')->where(array('order_id'=>$order_id))->select();
			  $v['count']=$count_ss[0]['count_goods'];

			  $this->assign('v',$v);
			  $this->assign('box_no',$box_no);
			  $this->assign('goods_text',$goods_text);
			  // dump($v);
			  $text_print=$this->fetch('Outbound/logistics/logistics_st');

			  $text[$k]=$text_print;
		  }
		  
		  $return['status']=1;
		  $return['info']=$text;
		  
		  
		  $this->ajaxReturn($return);
	}
	/**
	*出库申报
	**/
	public function pushoutboundstorage(){
		$m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$pushapi = A('Pushsendapi'); 
		$res=$pushapi->get_methodbatch();//出库申报
		$this->ajaxReturn($res);
	}
	
	//订单置顶、取消置顶
	public function set_arrow_status(){
		$m=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		$param=I('param.','','trim');
		$id=$param['id'];
		$value=$param['value'];
		$map['id']=array('in',$id);
		$data['arrow_status']=$value;//置顶状态1:是，0:否
		$res=$m->where($map)->save($data);
		
		if($res!==false){
			alert_json(1,'设置成功');
		}else{
			alert_json(0,'出错');
		}
	}
	
	//拦截
	Public function zintercepted(){
		  $Intercept=M('Intercept',C('DB_PRS'),C('DB_DEPOT'));
		  $InterceptOrder=M('InterceptOrder',C('DB_PRS'),C('DB_DEPOT'));
		  $Printorder=M('Printorder',C('DB_PRS'),C('DB_DEPOT'));
		  $Pushordergoods=M('Pushordergoods',C('DB_PRS'),C('DB_DEPOT'));
		  $Pushorder=M('Pushorder',C('DB_PRS'),C('DB_DEPOT'));
		  
		  $inter_list=$Intercept->where(array('status'=>1))->select();//获取拦截列表
		  $InterceptOrder->where('1')->delete();//删除所有拦截订单数据
		  
		  foreach($inter_list as $k=>$v){
			  $tval=$v['val'];
			  $tkey=$v['key'];
			  if($v['key']=='receiveProvince' or $v['key']=='receiveCity' or $v['key']=='receiveCounty'){  //按地区筛选订单号
				  $map[$tkey]=array('like',"%$tval%");
				  $map['status']=array('neq',-1);
				  $list_orderno=$Printorder->field('order_no')->where($map)->select();
				  foreach($list_orderno as $k => $v){
				  	  $data['order_no']=$v['order_no'];
				  	  if($v['order_no']){
				  		  $state=$InterceptOrder->where('order_no="'.$v['order_no'].'"')->find();
				  		  if($state==NULL){	//如果没有重复订单数据
				  			  $status=$InterceptOrder->add($data);
				  			  if($status){
				  				  continue;
				  			  }else{
								  alert_json(0,"出错");
				  			  }
				  		  }
				  	  }
				   }
			  }else if($v['key']=='goods_name'){			//按商品名称筛选订单号
				  $map[$tkey]=array('like',"%$tval%");
				  $list_orderid=$Pushordergoods->field('order_id')->where($map)->select();
				  foreach($list_orderid as $k=>$v){
					  $list_orno=$Pushorder->field('order_no')->where('id='.$v['order_id'])->find();
					  $data['order_no']=$list_orno['order_no'];
					  if($list_orno['order_no']){
						  $state=$InterceptOrder->where('order_no="'.$v['order_no'].'"')->find();
						  if($state==NULL){
							  $status=$InterceptOrder->add($data);
							  if($status){
								  continue;
							  }else{
								 alert_json(0,"出错");
							  }
						  }
					   }
				  }
			  }else if($v['key']=='order_no'){						//直接筛选订单号
						  $data['order_no']=$v['val'];
						  if($v['val']){
						  $state=$InterceptOrder->where('order_no="'.$v['val'].'"')->find();
							  if($state==NULL){
								  $status=$InterceptOrder->add($data);
								  if($status){
									  continue;
								  }else{
									 alert_json(0,"出错");
								  }
							  }
						  }
				}
		  }
		  
		  $list=$InterceptOrder->select();
		  return $list;
	  }
}